package com.hzeport.bgs22emduty.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzeport.bgs22emduty.config.SystemConfig;
import com.hzeport.bgs22emduty.config.exception.HdcException;
import com.hzeport.bgs22emduty.config.login.LoginCompoent;
import com.hzeport.bgs22emduty.config.login.LoginCompoentService;
import com.hzeport.bgs22emduty.config.login.UserInfoDetailVO;
import com.hzeport.bgs22emduty.dto.duty.DutyPersonInitDetailVO;
import com.hzeport.bgs22emduty.dto.duty.DutyPersonInitVO;
import com.hzeport.bgs22emduty.dto.duty.DutyRecordDetailTotalVO;
import com.hzeport.bgs22emduty.dto.duty.DutyRecordDetailVO;
import com.hzeport.bgs22emduty.entity.*;
import com.hzeport.bgs22emduty.enums.*;
import com.hzeport.bgs22emduty.outbound.*;
import com.hzeport.bgs22emduty.service.BaseDeptInfoService;
import com.hzeport.bgs22emduty.service.BasePersonInfoService;
import com.hzeport.bgs22emduty.util.DateUtil;
import com.hzeport.bgs22emduty.util.DutySortUtil;
import com.hzeport.bgs22emduty.util.GuavacacheUtils;
import com.hzeport.bgs22emduty.util.PersonCompareUtil;
import com.hzeport.bgs22emduty.vo.dudyScheduleSet.*;
import com.hzeport.bgs22emduty.common.base.BaseResult;
import com.hzeport.bgs22emduty.common.base.BaseServiceImpl;
import com.hzeport.bgs22emduty.outbound.db.DutyScheduleSetRepositoryImpl;
import com.hzeport.bgs22emduty.service.DutyScheduleSetService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * ${comments}
 *
 * @author code generator
 * @date 2022-12-02 11:21:59
 */
@Service
@Slf4j
public class DutyScheduleSetServiceImpl extends BaseServiceImpl<DutyScheduleSetRepositoryImpl, DutyScheduleSet> implements DutyScheduleSetService {

    @Resource
    private DutyScheduleSetRepository dutyScheduleSetRepository;
    @Resource
    private DutyScheduleSetCustomRepository dutyScheduleSetCustomRepository;
    @Resource
    private ParamHolidaysRepository paramHolidaysRepository;
    @Resource
    private DutyScheduleInfoRepository dutyScheduleInfoRepository;
    @Resource
    private ParamLeaderRepository paramLeaderRepository;
    @Resource
    private BaseDeptInfoRepository baseDeptInfoRepository;
    @Resource
    private BasePersonInfoRepository basePersonInfoRepository;
    @Resource
    private ParamDutyRepository paramDutyRepository;
    @Resource
    private BaseDeptTypeRepository baseDeptTypeRepository;
    @Resource
    private BaseDeptInfoService baseDeptInfoService;
    @Resource
    private DutyScheduleSetCustomRecordRepository dutyScheduleSetCustomRecordRepository;
    @Resource
    private GuavacacheUtils guavacacheUtils;
    @Resource
    private SystemConfig systemConfig;
    @Resource
    private BasePersonInfoService basePersonInfoService;
    @Resource
    private ParamScheduleSettingRepository paramScheduleSettingRepository;
    @Resource
    private ParamGroupDutyRepository paramGroupDutyRepository;
    @Resource
    private DutySignInfoRepository dutySignInfoRepository;
    @Resource
    private LoginCompoentService loginCompoentService;
    @Resource
    private DutySortUtil dutySortUtil;

    @Resource
    private DutyScheduleGroupRecordRepository dutyScheduleGroupRecordRepository;

    @Override
    public Object dudyScheduleSetList(DudyScheduleSetListVO dudyScheduleSetListVO) {
        LambdaQueryWrapper<DutyScheduleSetCustom> lambdaQueryWrapper = new LambdaQueryWrapper<DutyScheduleSetCustom>();
        if (!CollectionUtils.isEmpty(dudyScheduleSetListVO.getYear())) {
            String[] tempArray = dudyScheduleSetListVO.getYear().get(0).split("-");
            Long startYear = Long.valueOf(tempArray[0]);
            Long startMonth = Long.valueOf(tempArray[1]);
            tempArray = dudyScheduleSetListVO.getYear().get(1).split("-");
            Long endYear = Long.valueOf(tempArray[0]);
            Long endMonth = Long.valueOf(tempArray[1]);
            lambdaQueryWrapper
                    .and(wrapper ->
                            wrapper.ge(DutyScheduleSetCustom::getStartDate, LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1))
                                    .le(DutyScheduleSetCustom::getStartDate, LocalDate.of((int) (long) endYear, (int) (long) endMonth, 1))
                                    .or(orwrapper -> orwrapper.ge(DutyScheduleSetCustom::getEndDate, LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1))
                                            .le(DutyScheduleSetCustom::getEndDate, LocalDate.of((int) (long) endYear, (int) (long) endMonth, 1))
                                    ));
        }
        lambdaQueryWrapper.eq(DutyScheduleSetCustom::getCustomId, dudyScheduleSetListVO.getCustomId());
        lambdaQueryWrapper.orderByDesc(DutyScheduleSetCustom::getSYearEnd)
                .orderByDesc(DutyScheduleSetCustom::getSMonthEnd);
        Page page = new Page(dudyScheduleSetListVO.getPageNum(), dudyScheduleSetListVO.getPageSize());
        List<DutyScheduleSetCustom> dutyScheduleSetCustoms = dutyScheduleSetCustomRepository.list(lambdaQueryWrapper);
        ListIterator<DutyScheduleSetCustom> dutyScheduleSetCustomListIterator = dutyScheduleSetCustoms.listIterator();
        while (dutyScheduleSetCustomListIterator.hasNext()) {
            DutyScheduleSetCustom dutyScheduleSetCustom = dutyScheduleSetCustomListIterator.next();
            dutyScheduleSetCustom.setSType("1");
            dutyScheduleSetCustom.setMonth(dutyScheduleSetCustom.getSYearStart() + "-" + dutyScheduleSetCustom.getSMonthStart() + "---"
                    + dutyScheduleSetCustom.getSYearEnd() + "-" + dutyScheduleSetCustom.getSMonthEnd());
        }
        Page<DutyScheduleSetCustom> dutyScheduleSetCustomPage = new Page<DutyScheduleSetCustom>();
        dutyScheduleSetCustomPage.setTotal(dutyScheduleSetCustoms.size());
        dutyScheduleSetCustomPage.setRecords(dutyScheduleSetCustoms);
        return dutyScheduleSetCustomPage;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Object saveList(DutyScheduleSetSaveVO dudyScheduleSetSaveVO, UserInfoDetailVO userInfoDetailVO, Boolean isReinit) throws Exception {
        DutyScheduleSetCustom dutyScheduleSetCustom = new DutyScheduleSetCustom();
        BeanUtils.copyProperties(dudyScheduleSetSaveVO, dutyScheduleSetCustom);
        String[] tempArray = dudyScheduleSetSaveVO.getSMonths().get(0).split("-");
        Long startYear = Long.valueOf(tempArray[0]);
        Long startMonth = Long.valueOf(tempArray[1]);
        tempArray = dudyScheduleSetSaveVO.getSMonths().get(1).split("-");
        Long endYear = Long.valueOf(tempArray[0]);
        Long endMonth = Long.valueOf(tempArray[1]);
        if (endMonth < 12) {
            endMonth = endMonth + 1;
        } else {
            endMonth = 1l;
            endYear = endYear + 1;
        }
        Long finalEndYear = endYear;
        Long finalEndMonth = endMonth;
        LambdaQueryWrapper<DutyScheduleSetCustom> queryWrapper = new LambdaQueryWrapper<DutyScheduleSetCustom>()
                .and(wrapper ->
                        wrapper.ge(DutyScheduleSetCustom::getStartDate, LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1))
                                .le(DutyScheduleSetCustom::getStartDate, LocalDate.of((int) (long) finalEndYear, (int) (long) finalEndMonth, 1).minusDays(1))
                                .or(orwrapper -> orwrapper.ge(DutyScheduleSetCustom::getEndDate, LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1))
                                        .le(DutyScheduleSetCustom::getEndDate, LocalDate.of((int) (long) finalEndYear, (int) (long) finalEndMonth, 1).minusDays(1))
                                )
                );
        queryWrapper.eq(DutyScheduleSetCustom::getCustomId, dudyScheduleSetSaveVO.getCustomId());
        if (dudyScheduleSetSaveVO.getId() != null) {
            queryWrapper.ne(DutyScheduleSetCustom::getId, dudyScheduleSetSaveVO.getId());
        }
        List<DutyScheduleSetCustom> stationInfos = dutyScheduleSetCustomRepository.list(queryWrapper);
        if (!CollectionUtils.isEmpty(stationInfos)) {
            throw new HdcException("年份和月份不能重复");
        }
        if (dudyScheduleSetSaveVO.getDudyScheduleListVO() != null) {
            //todo
            checkBodys(dudyScheduleSetSaveVO.getDudyScheduleListVO(), dudyScheduleSetSaveVO);
        } else {
            throw new HdcException("夜班和假日班配置至少应有一条!");
        }
        List<ParamScheduleSetting> paramScheduleSettingListTYPE_RC = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, userInfoDetailVO.getCustomscode())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_RC.getValue()));
        List<ParamScheduleSetting> paramScheduleSettingListTYPE_ZMB = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, userInfoDetailVO.getCustomscode())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_ZMB.getValue()));
        List<ParamScheduleSetting> paramScheduleSettingListTYPE_ZYB = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, userInfoDetailVO.getCustomscode())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_ZYB.getValue()));
        List<ParamScheduleSetting> paramScheduleSettingListTYPE_ZM = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, userInfoDetailVO.getCustomscode())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_ZM.getValue()));
        if (CollectionUtils.isEmpty(paramScheduleSettingListTYPE_RC)) {
            throw new HdcException("工作日班未进行排班配置!");
        }
        if (CollectionUtils.isEmpty(paramScheduleSettingListTYPE_ZMB)) {
            throw new HdcException("节假日班未进行排班配置!");
        }
        if (CollectionUtils.isEmpty(paramScheduleSettingListTYPE_ZYB)) {
            throw new HdcException("重要班未进行排班配置!");
        }
        if (CollectionUtils.isEmpty(paramScheduleSettingListTYPE_ZM)) {
            throw new HdcException("周末班未进行排班配置!");
        }
        if (StringUtils.isEmpty(dutyScheduleSetCustom.getId())) {
            if (endMonth == 1l) {
                endMonth = 12l;
                endYear = endYear - 1;
            } else {
                endMonth = endMonth - 1;
            }
            dutyScheduleSetCustom.setUpdateBy(userInfoDetailVO.getUserId());
            dutyScheduleSetCustom.setUpdateTime(LocalDateTime.now());
            dutyScheduleSetCustom.setSMonthStart(startMonth);
            dutyScheduleSetCustom.setSYearStart(startYear);
            dutyScheduleSetCustom.setSMonthEnd(endMonth);
            dutyScheduleSetCustom.setSYearEnd(endYear);
            dutyScheduleSetCustom.setStartDate(LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1));
            dutyScheduleSetCustom.setEndDate(LocalDate.of((int) (long) endYear, (int) (long) endMonth, 1));
            dutyScheduleSetCustom.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
            dutyScheduleSetCustom.setTemplateJson(JSONObject.toJSONString(dudyScheduleSetSaveVO.getDudyScheduleListVO()));
            dutyScheduleSetCustomRepository.save(dutyScheduleSetCustom);
        } else {
            if (endMonth == 1l) {
                endMonth = 12l;
                endYear = endYear - 1;
            } else {
                endMonth = endMonth - 1;
            }
            DutyScheduleSetCustom byId = dutyScheduleSetCustomRepository.getById(dutyScheduleSetCustom.getId());
            dutyScheduleSetCustom.setSMonthStart(startMonth);
            dutyScheduleSetCustom.setSYearStart(startYear);
            dutyScheduleSetCustom.setSMonthEnd(endMonth);
            dutyScheduleSetCustom.setSYearEnd(endYear);
            dutyScheduleSetCustom.setUpdateBy(userInfoDetailVO.getUserId());
            dutyScheduleSetCustom.setUpdateTime(LocalDateTime.now());
            dutyScheduleSetCustom.setStartDate(LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1));
            dutyScheduleSetCustom.setEndDate(LocalDate.of((int) (long) endYear, (int) (long) endMonth, 1));
            dutyScheduleSetCustom.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
            dutyScheduleSetCustom.setTemplateJson(JSONObject.toJSONString(dudyScheduleSetSaveVO.getDudyScheduleListVO()));
            if (byId != null){
                dutyScheduleSetCustom.setRecVersion(dutyScheduleSetCustom.getRecVersion());
            }
            dutyScheduleSetCustomRepository.updateById(dutyScheduleSetCustom);
            dutyScheduleSetRepository.remove(new LambdaQueryWrapper<DutyScheduleSet>()
                    .eq(DutyScheduleSet::getSetCustomId, dutyScheduleSetCustom.getId()));
        }
        List<DutyScheduleSet> YBList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(dudyScheduleSetSaveVO.getDudyScheduleListVO().getDailyDudy().getDudyTemplate())) {
            for (DudyScheduleListVO.DudyTemplate dutyScheduleSetSaveDetailVO : dudyScheduleSetSaveVO.getDudyScheduleListVO().getDailyDudy().getDudyTemplate()) {
                DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
                BeanUtils.copyProperties(dutyScheduleSetSaveDetailVO, dutyScheduleSet);
                dutyScheduleSet.setId(null);
                dutyScheduleSet.setCreateTime(LocalDateTime.now());
                dutyScheduleSet.setCreateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setSCount((long) dutyScheduleSetSaveDetailVO.getSectionLevelDudyNumber());
                dutyScheduleSet.setDCount((long) dutyScheduleSetSaveDetailVO.getDivisionLevelDudyNumber());
                dutyScheduleSet.setDeptId(dutyScheduleSetSaveDetailVO.getDudyDeptId());
                dutyScheduleSet.setSDept(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setDeptName(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setUpdateTime(LocalDateTime.now());
                dutyScheduleSet.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
                dutyScheduleSet.setUpdateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setSetCustomId(dutyScheduleSetCustom.getId());
                dutyScheduleSet.setSType(STypeEnum.TYPE_WB.getValue());
                dutyScheduleSetRepository.save(dutyScheduleSet);
                YBList.add(dutyScheduleSet);
            }
        }
        List<DutyScheduleSet> ZMBList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(dudyScheduleSetSaveVO.getDudyScheduleListVO().getHolidayAndVacationsDudy().getDudyTemplate())) {
            for (DudyScheduleListVO.DudyTemplate dutyScheduleSetSaveDetailVO : dudyScheduleSetSaveVO.getDudyScheduleListVO().getHolidayAndVacationsDudy().getDudyTemplate()) {
                DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
                BeanUtils.copyProperties(dutyScheduleSetSaveDetailVO, dutyScheduleSet);
                dutyScheduleSet.setId(null);
                dutyScheduleSet.setSCount((long) dutyScheduleSetSaveDetailVO.getSectionLevelDudyNumber());
                dutyScheduleSet.setDCount((long) dutyScheduleSetSaveDetailVO.getDivisionLevelDudyNumber());
                dutyScheduleSet.setDeptId(dutyScheduleSetSaveDetailVO.getDudyDeptId());
                dutyScheduleSet.setDeptName(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setSDept(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setCreateTime(LocalDateTime.now());
                dutyScheduleSet.setCreateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setUpdateTime(LocalDateTime.now());
                dutyScheduleSet.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
                dutyScheduleSet.setUpdateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setSetCustomId(dutyScheduleSetCustom.getId());
                dutyScheduleSet.setSType(STypeEnum.TYPE_ZMB.getValue());
                dutyScheduleSetRepository.save(dutyScheduleSet);
                ZMBList.add(dutyScheduleSet);
            }
        }
        List<DutyScheduleSet> ZYBList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(dudyScheduleSetSaveVO.getDudyScheduleListVO().getImportantDayDudy().getDudyTemplate())) {
            for (DudyScheduleListVO.DudyTemplate dutyScheduleSetSaveDetailVO : dudyScheduleSetSaveVO.getDudyScheduleListVO().getImportantDayDudy().getDudyTemplate()) {
                DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
                BeanUtils.copyProperties(dutyScheduleSetSaveDetailVO, dutyScheduleSet);
                dutyScheduleSet.setId(null);
                dutyScheduleSet.setSCount((long) dutyScheduleSetSaveDetailVO.getSectionLevelDudyNumber());
                dutyScheduleSet.setDCount((long) dutyScheduleSetSaveDetailVO.getDivisionLevelDudyNumber());
                dutyScheduleSet.setSDept(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setDeptId(dutyScheduleSetSaveDetailVO.getDudyDeptId());
                dutyScheduleSet.setDeptName(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setCreateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setDeptId(dutyScheduleSet.getDeptId());
                dutyScheduleSet.setUpdateTime(LocalDateTime.now());
                dutyScheduleSet.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
                dutyScheduleSet.setUpdateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setSetCustomId(dutyScheduleSetCustom.getId());
                dutyScheduleSet.setSType(STypeEnum.TYPE_ZYB.getValue());
                dutyScheduleSetRepository.save(dutyScheduleSet);
                ZYBList.add(dutyScheduleSet);
            }
        }
        List<DutyScheduleSet> ZMList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(dudyScheduleSetSaveVO.getDudyScheduleListVO().getWeekendDudy().getDudyTemplate())) {
            for (DudyScheduleListVO.DudyTemplate dutyScheduleSetSaveDetailVO : dudyScheduleSetSaveVO.getDudyScheduleListVO().getWeekendDudy().getDudyTemplate()) {
                DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
                BeanUtils.copyProperties(dutyScheduleSetSaveDetailVO, dutyScheduleSet);
                dutyScheduleSet.setId(null);
                dutyScheduleSet.setSCount((long) dutyScheduleSetSaveDetailVO.getSectionLevelDudyNumber());
                dutyScheduleSet.setDCount((long) dutyScheduleSetSaveDetailVO.getDivisionLevelDudyNumber());
                dutyScheduleSet.setSDept(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setDeptId(dutyScheduleSetSaveDetailVO.getDudyDeptId());
                dutyScheduleSet.setDeptName(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setCreateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setDeptId(dutyScheduleSet.getDeptId());
                dutyScheduleSet.setUpdateTime(LocalDateTime.now());
                dutyScheduleSet.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
                dutyScheduleSet.setUpdateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setSetCustomId(dutyScheduleSetCustom.getId());
                dutyScheduleSet.setSType(STypeEnum.TYPE_ZM.getValue());
                dutyScheduleSetRepository.save(dutyScheduleSet);
                ZMList.add(dutyScheduleSet);
            }
        }
        List<DutyPersonInitVO> dutyScheduleSetDetailVOS = dudyScheduleSetSaveVO.getDutyPersonInitVOS();
        List<DutyScheduleGroupRecord> dutyScheduleGroupRecords = new ArrayList<>();
        for (DutyPersonInitVO dutyScheduleSetDetailVO : dutyScheduleSetDetailVOS) {
            DutyScheduleGroupRecord dutyScheduleGroupRecord = new DutyScheduleGroupRecord();
            dutyScheduleGroupRecord.setCustomId(dudyScheduleSetSaveVO.getCustomId());
            dutyScheduleGroupRecord.setDutyType(dutyScheduleSetDetailVO.getDutyType());
            dutyScheduleGroupRecord.setSeType(dutyScheduleSetDetailVO.getSeType());
//                dutyScheduleGroupRecord.setLastPersonName(dutyScheduleSetDetailVO.getPersonName());
            dutyScheduleGroupRecord.setLastPersonNo(dutyScheduleSetDetailVO.getPersonNo());
            dutyScheduleGroupRecord.setLastPersonSort(dutyScheduleSetDetailVO.getGlobalSort());
            dutyScheduleGroupRecord.setDelFlag("0");
            dutyScheduleGroupRecord.setCreateTime(LocalDateTime.now());
            dutyScheduleGroupRecord.setSetCustomId(dutyScheduleSetCustom.getId());
            dutyScheduleGroupRecords.add(dutyScheduleGroupRecord);
        }
        if (SStatusEnum.TYPE_SUBMIT.getValue().equals(dudyScheduleSetSaveVO.getSStatus())) {
            createPersons(dudyScheduleSetSaveVO, YBList, ZMBList, ZYBList, ZMList, dutyScheduleSetCustom.getId(), startMonth, startYear, endYear, endMonth, isReinit, dudyScheduleSetSaveVO.getDutyPersonInitVOS(), dutyScheduleGroupRecords);
        }
        dutyScheduleGroupRecordRepository.remove(new LambdaQueryWrapper<DutyScheduleGroupRecord>()
                .eq(DutyScheduleGroupRecord::getCustomId, dudyScheduleSetSaveVO.getCustomId())
                .eq(DutyScheduleGroupRecord::getSetCustomId, dudyScheduleSetSaveVO.getId()));

        dutyScheduleGroupRecordRepository.saveBatch(dutyScheduleGroupRecords);
        return true;
    }

    /**
     * 排班生成上下文对象，封装公共参数
     */
    private static class DutyScheduleContext {
        private final BaseDeptInfo custom;
        private final List<ParamHolidays> holidays;
        private final List<ParamHolidays> importantDays;
        private final List<ParamHolidays> exchangeDays;
        private final List<BaseDeptInfo> allDepts;
        private final List<BaseDeptInfo> baseDeptInfos;
        private final List<ParamGroupDuty> paramGroupDuties;
        private final Long sYear;
        private final Long sMonth;
        private final Long endYear;
        private final Long endMonth;
        private final String customId;

        public DutyScheduleContext(BaseDeptInfo custom, List<ParamHolidays> holidays,
                                   List<ParamHolidays> importantDays, List<ParamHolidays> exchangeDays,
                                   List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos,
                                   List<ParamGroupDuty> paramGroupDuties, Long sYear, Long sMonth,
                                   Long endYear, Long endMonth, String customId) {
            this.custom = custom;
            this.holidays = holidays;
            this.importantDays = importantDays;
            this.exchangeDays = exchangeDays;
            this.allDepts = allDepts;
            this.baseDeptInfos = baseDeptInfos;
            this.paramGroupDuties = paramGroupDuties;
            this.sYear = sYear;
            this.sMonth = sMonth;
            this.endYear = endYear;
            this.endMonth = endMonth;
            this.customId = customId;
        }

        // Getters
        public BaseDeptInfo getCustom() { return custom; }
        public List<ParamHolidays> getHolidays() { return holidays; }
        public List<ParamHolidays> getImportantDays() { return importantDays; }
        public List<ParamHolidays> getExchangeDays() { return exchangeDays; }
        public List<BaseDeptInfo> getAllDepts() { return allDepts; }
        public List<BaseDeptInfo> getBaseDeptInfos() { return baseDeptInfos; }
        public List<ParamGroupDuty> getParamGroupDuties() { return paramGroupDuties; }
        public Long getSYear() { return sYear; }
        public Long getSMonth() { return sMonth; }
        public Long getEndYear() { return endYear; }
        public Long getEndMonth() { return endMonth; }
        public String getCustomId() { return customId; }
    }


    /**
     * 初始化排班上下文
     */
    private DutyScheduleContext initScheduleContext(DutyScheduleSetSaveVO dudyScheduleSetSaveVO,
                                                     Long sMonth, Long sYear, Long endYear, Long endMonth) {
        BaseDeptInfo custom = baseDeptInfoRepository.getById(dudyScheduleSetSaveVO.getCustomId());
        Long adjustedEndMonth = endMonth;
        Long adjustedEndYear = endYear;
        if (endMonth < 12) {
            adjustedEndMonth = endMonth + 1;
        } else {
            adjustedEndMonth = 1L;
            adjustedEndYear = endYear + 1;
        }

        List<ParamHolidays> holidays = paramHolidaysRepository.list(new LambdaQueryWrapper<ParamHolidays>()
                .ge(ParamHolidays::getHolidayDate, LocalDate.of(sYear.intValue(), sMonth.intValue(), 1))
                .lt(ParamHolidays::getHolidayDate, LocalDate.of(adjustedEndYear.intValue(), adjustedEndMonth.intValue(), 1))
                .eq(ParamHolidays::getCustomId, dudyScheduleSetSaveVO.getCustomId())
                .eq(ParamHolidays::getHolidayType, HolidaysEnum.HOLIDAY.getValue()));

        List<ParamHolidays> importantDays = paramHolidaysRepository.list(new LambdaQueryWrapper<ParamHolidays>()
                .ge(ParamHolidays::getHolidayDate, LocalDate.of(sYear.intValue(), sMonth.intValue(), 1))
                .lt(ParamHolidays::getHolidayDate, LocalDate.of(adjustedEndYear.intValue(), adjustedEndMonth.intValue(), 1))
                .eq(ParamHolidays::getCustomId, dudyScheduleSetSaveVO.getCustomId())
                .eq(ParamHolidays::getHolidayType, HolidaysEnum.IMPORTANT_PERIOD.getValue()));

        List<ParamHolidays> exchangeDays = paramHolidaysRepository.list(new LambdaQueryWrapper<ParamHolidays>()
                .ge(ParamHolidays::getHolidayDate, LocalDate.of(sYear.intValue(), sMonth.intValue(), 1))
                .lt(ParamHolidays::getHolidayDate, LocalDate.of(adjustedEndYear.intValue(), adjustedEndMonth.intValue(), 1))
                .eq(ParamHolidays::getCustomId, dudyScheduleSetSaveVO.getCustomId())
                .eq(ParamHolidays::getHolidayType, HolidaysEnum.HOLIDAY_EXCHANGE.getValue()));

        List<BaseDeptInfo> allDepts = baseDeptInfoRepository.list(new LambdaQueryWrapper<BaseDeptInfo>()
                .eq(BaseDeptInfo::getCustomId, dudyScheduleSetSaveVO.getCustomId()));

        List<BaseDeptInfo> baseDeptInfos = baseDeptInfoRepository.list(new LambdaQueryWrapper<BaseDeptInfo>()
                .eq(BaseDeptInfo::getParentid, dudyScheduleSetSaveVO.getCustomId())
                .orderByAsc(BaseDeptInfo::getGlobalSort));

        List<ParamGroupDuty> paramGroupDuties = paramGroupDutyRepository.list(new LambdaQueryWrapper<ParamGroupDuty>()
                .eq(ParamGroupDuty::getCustomId, custom.getId()));

        return new DutyScheduleContext(custom, holidays, importantDays, exchangeDays, allDepts,
                baseDeptInfos, paramGroupDuties, sYear, sMonth, adjustedEndYear, adjustedEndMonth,
                dudyScheduleSetSaveVO.getCustomId());
    }

    /**
     * 生成部门模板
     */
    private List<DudyScheduleListVO.DudyTemplate> generateDeptTemplates(List<BasePersonInfo> persons,
                                                                          List<BaseDeptInfo> baseDeptInfos,
                                                                          List<BaseDeptInfo> allDepts,
                                                                          boolean useSectionLevel) {
            List<DudyScheduleListVO.DudyTemplate> deptTemplates = new ArrayList<>();
        for (BaseDeptInfo deptInfo : baseDeptInfos) {
                DudyScheduleListVO.DudyTemplate dudyTemplate = new DudyScheduleListVO.DudyTemplate();
            List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, deptInfo, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
            if (useSectionLevel) {
                dudyTemplate.setSectionLevelDudyNumber(thisDept.size());
            } else {
                dudyTemplate.setDivisionLevelDudyNumber(thisDept.size());
            }
            dudyTemplate.setDudyDeptId(deptInfo.getId());
            dudyTemplate.setDudyDept(deptInfo.getDeptName());
            dudyTemplate.setSort(deptInfo.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
        return deptTemplates;
    }

    /**
     * 通用的排班生成逻辑（用于科员级别的各种班型）
     * @param context 排班上下文
     * @param seType 人员级别
     * @param dutyType 班型类型
     * @param scheduleList 排班列表
     * @param useSCount 是否使用SCount（true为科级，false为处级）
     * @param dutyPersonInitDetailVOS 初始化人员列表
     * @param dutyScheduleInfos 排班信息列表（输出）
     * @param dutyScheduleGroupRecords 排班群组记录（输出）
     * @param dayScheduleSupplier 日期排班信息提供者（lambda表达式）
     */
    private void generateScheduleForSectionLevel(DutyScheduleContext context, String seType, String dutyType,
                                                 List<DutyScheduleSet> scheduleList, boolean useSCount,
                                                 List<DutyPersonInitVO> dutyPersonInitDetailVOS,
                                                 List<DutyScheduleInfo> dutyScheduleInfos,
                                                 List<DutyScheduleGroupRecord> dutyScheduleGroupRecords,
                                                 ScheduleDaySupplier dayScheduleSupplier) throws Exception {
        // 检查是否有对应的群组配置
        List<ParamGroupDuty> groupDuties = context.getParamGroupDuties().stream()
                .filter(i -> seType.equals(i.getSeType()) && dutyType.equals(i.getSType()))
                .collect(Collectors.toList());

        if (CollectionUtils.isEmpty(groupDuties)) {
            return;
        }

        // 获取初始化人员和参与排班的人员
        DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream()
                .filter(j -> dutyType.equals(j.getDutyType()) && seType.equals(j.getSeType()))
                .findAny().orElse(null);

        List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(
                context.getCustom().getId(), seType, dutyType);

        // 生成部门模板
        List<DudyScheduleListVO.DudyTemplate> deptTemplates = generateDeptTemplates(
                persons, context.getBaseDeptInfos(), context.getAllDepts(), useSCount);

        // 计算总人数
        long totalCount = scheduleList.stream()
                .map(useSCount ? DutyScheduleSet::getSCount : DutyScheduleSet::getDCount)
                .reduce(Long::sum)
                .orElse(0L);

        if (totalCount == 0) {
            return;
        }

        // 创建线性模板（根据是否使用SCount选择不同的方法）
        List<DudyScheduleListVO.DudyTemplate> dudyTemplates;
        if (useSCount) {
            dudyTemplates = createLineTemplates(scheduleList, null, dutyPersonInitVO, persons,
                    context.getAllDepts(), context.getBaseDeptInfos(), deptTemplates);
        } else {
            dudyTemplates = createLineTemplatesForD(scheduleList, null, dutyPersonInitVO, persons,
                    context.getAllDepts(), context.getBaseDeptInfos(), deptTemplates);
        }

        // 循环生成排班
        for (int i = 1; i <= totalCount; i++) {
            // 验证人员
                    if (CollectionUtils.isEmpty(persons)) {
                throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + seType + dutyType);
            }
            if (dutyPersonInitVO == null || dutyPersonInitVO.getPersonNo() == null) {
                throw new Exception("无法获取人员，请确认配置了值班起始人员" + seType + dutyType);
            }

            // 获取当天的排班信息（通过supplier提供）
            List<DutyScheduleInfo> scheduleInfos = dayScheduleSupplier.getDaySchedule(i, scheduleList, dudyTemplates,
                    deptTemplates, persons, dutyPersonInitVO);

                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                scheduleInfos = scheduleInfos.stream()
                        .sorted(Comparator.comparing(DutyScheduleInfo::getDEndDateTime))
                .collect(Collectors.toList());

                // 记录最后一次排班的最终人员信息
                        if (i == totalCount) {
                    DutyScheduleGroupRecord record = dutyScheduleGroupRecords.stream()
                            .filter(j -> j.getSeType().contains(seType) && j.getDutyType().contains(dutyType))
                            .findAny()
                            .orElse(new DutyScheduleGroupRecord());
                    DutyScheduleInfo lastSchedule = scheduleInfos.get(scheduleInfos.size() - 1);
                    record.setFinalPersonName(lastSchedule.getDUsername())
                          .setFinalPersonNo(lastSchedule.getDUserno())
                          .setFinalPersonSort(lastSchedule.getGlobalSort());
                }
            }
        }
    }

    /**
     * 通用的排班生成逻辑（用于处级级别的各种班型）
     */
    private void generateScheduleForDivisionLevel(DutyScheduleContext context, String seType, String dutyType,
                                                  List<DutyScheduleSet> scheduleList,
                                                  List<DutyPersonInitVO> dutyPersonInitDetailVOS,
                                                  List<DutyScheduleInfo> dutyScheduleInfos,
                                                  List<DutyScheduleGroupRecord> dutyScheduleGroupRecords,
                                                  ScheduleDaySupplier dayScheduleSupplier) throws Exception {
        // 检查是否有对应的群组配置
        List<ParamGroupDuty> groupDuties = context.getParamGroupDuties().stream()
                .filter(i -> seType.equals(i.getSeType()) && dutyType.equals(i.getSType()))
                .collect(Collectors.toList());

        if (CollectionUtils.isEmpty(groupDuties)) {
            return;
        }

        // 获取初始化人员和参与排班的人员
        DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream()
                .filter(j -> dutyType.equals(j.getDutyType()) && seType.equals(j.getSeType()))
                .findAny().orElse(null);

        List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(
                context.getCustom().getId(), seType, dutyType);

        // 生成部门模板（处级使用DivisionLevelDutyNumber）
        List<DudyScheduleListVO.DudyTemplate> deptTemplates = generateDeptTemplates(
                persons, context.getBaseDeptInfos(), context.getAllDepts(), false);

        // 计算总人数（处级使用DCount）
        long totalCount = scheduleList.stream()
                .map(DutyScheduleSet::getDCount)
                .reduce(Long::sum)
                .orElse(0L);

        if (totalCount == 0) {
            return;
        }

        // 创建线性模板（处级使用createLineTemplatesForD）
        List<DudyScheduleListVO.DudyTemplate> dudyTemplates = createLineTemplatesForD(scheduleList, null, dutyPersonInitVO,
                persons, context.getAllDepts(), context.getBaseDeptInfos(), deptTemplates);

        // 循环生成排班
        for (int i = 1; i <= totalCount; i++) {
            // 验证人员
                    if (CollectionUtils.isEmpty(persons)) {
                throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + seType + dutyType);
            }
            if (dutyPersonInitVO == null || dutyPersonInitVO.getPersonNo() == null) {
                throw new Exception("无法获取人员，请确认配置了值班起始人员" + seType + dutyType);
            }

            // 获取当天的排班信息（通过supplier提供）
            List<DutyScheduleInfo> scheduleInfos = dayScheduleSupplier.getDaySchedule(i, scheduleList, dudyTemplates,
                    deptTemplates, persons, dutyPersonInitVO);

                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                scheduleInfos = scheduleInfos.stream()
                        .sorted(Comparator.comparing(DutyScheduleInfo::getDEndDateTime))
                        .collect(Collectors.toList());

                // 记录最后一次排班的最终人员信息
                        if (i == totalCount) {
                    DutyScheduleGroupRecord record = dutyScheduleGroupRecords.stream()
                            .filter(j -> j.getSeType().contains(seType) && j.getDutyType().contains(dutyType))
                            .findAny()
                            .orElse(new DutyScheduleGroupRecord());
                    DutyScheduleInfo lastSchedule = scheduleInfos.get(scheduleInfos.size() - 1);
                    record.setFinalPersonName(lastSchedule.getDUsername())
                          .setFinalPersonNo(lastSchedule.getDUserno())
                          .setFinalPersonSort(lastSchedule.getGlobalSort());
                }
            }
        }
    }

    /**
     * 通用的排班生成逻辑（用于关领导级别的各种班型，使用计算出的日期数量而不是totalCount）
     * @param context 排班上下文
     * @param seType 人员级别
     * @param dutyType 班型类型
     * @param scheduleList 排班列表
     * @param totalCount 总数量（计算出的日期数量）
     * @param dutyPersonInitDetailVOS 初始化人员列表
     * @param dutyScheduleInfos 排班信息列表（输出）
     * @param dutyScheduleGroupRecords 排班群组记录（输出）
     * @param dayScheduleSupplier 日期排班信息提供者（lambda表达式）
     */
    private void generateScheduleForLeaderLevel(DutyScheduleContext context, String seType, String dutyType,
                                                List<DutyScheduleSet> scheduleList, Integer totalCount,
                                                List<DutyPersonInitVO> dutyPersonInitDetailVOS,
                                                List<DutyScheduleInfo> dutyScheduleInfos,
                                                List<DutyScheduleGroupRecord> dutyScheduleGroupRecords,
                                                ScheduleDaySupplier dayScheduleSupplier) throws Exception {
        // 检查是否有对应的群组配置
        List<ParamGroupDuty> groupDuties = context.getParamGroupDuties().stream()
                .filter(i -> seType.equals(i.getSeType()) && dutyType.equals(i.getSType()))
                .collect(Collectors.toList());

        if (CollectionUtils.isEmpty(groupDuties) || totalCount == null || totalCount <= 0) {
            return;
        }

        // 获取初始化人员和参与排班的人员
        DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream()
                .filter(j -> dutyType.equals(j.getDutyType()) && seType.equals(j.getSeType()))
                .findAny().orElse(null);

        List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(
                context.getCustom().getId(), seType, dutyType);

        // 生成部门模板（关领导使用SectionLevelDutyNumber）
        List<DudyScheduleListVO.DudyTemplate> deptTemplates = generateDeptTemplates(
                persons, context.getBaseDeptInfos(), context.getAllDepts(), true);

        // 循环生成排班（不使用线性模板，直接使用null）
        for (int i = 1; i <= totalCount; i++) {
            // 验证人员
                    if (CollectionUtils.isEmpty(persons)) {
                throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + seType + dutyType);
            }
            if (dutyPersonInitVO == null || dutyPersonInitVO.getPersonNo() == null) {
                throw new Exception("无法获取人员，请确认配置了值班起始人员" + seType + dutyType);
            }

            // 获取当天的排班信息（通过supplier提供，关领导级别不使用dudyTemplates，传入null）
            List<DutyScheduleInfo> scheduleInfos = dayScheduleSupplier.getDaySchedule(i, scheduleList, null,
                    deptTemplates, persons, dutyPersonInitVO);

                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                scheduleInfos = scheduleInfos.stream()
                        .sorted(Comparator.comparing(DutyScheduleInfo::getDEndDateTime))
                        .collect(Collectors.toList());

                // 记录最后一次排班的最终人员信息
                        if (i == totalCount) {
                    DutyScheduleGroupRecord record = dutyScheduleGroupRecords.stream()
                            .filter(j -> j.getSeType().contains(seType) && j.getDutyType().contains(dutyType))
                            .findAny()
                            .orElse(new DutyScheduleGroupRecord());
                    DutyScheduleInfo lastSchedule = scheduleInfos.get(scheduleInfos.size() - 1);
                    record.setFinalPersonName(lastSchedule.getDUsername())
                          .setFinalPersonNo(lastSchedule.getDUserno())
                          .setFinalPersonSort(lastSchedule.getGlobalSort());
                }
            }
        }
    }

    /**
     * 日期排班信息提供者接口（函数式接口）
     */
    @FunctionalInterface
    private interface ScheduleDaySupplier {
        List<DutyScheduleInfo> getDaySchedule(int dayIndex, List<DutyScheduleSet> scheduleList,
                                              List<DudyScheduleListVO.DudyTemplate> dudyTemplates,
                                              List<DudyScheduleListVO.DudyTemplate> deptTemplates,
                                              List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) throws Exception;
    }

    private void createPersons(DutyScheduleSetSaveVO dudyScheduleSetSaveVO, List<DutyScheduleSet> YBList, List<DutyScheduleSet> ZMBList, List<DutyScheduleSet> ZYBList, List<DutyScheduleSet> ZMList, String id, Long sMonth, Long sYear, Long endYear, Long endMonth, Boolean isReinit, List<DutyPersonInitVO> dutyPersonInitDetailVOS, List<DutyScheduleGroupRecord> dutyScheduleGroupRecords) throws Exception {
        List<DutyScheduleInfo> dutyScheduleInfos = new ArrayList<>();
        
        // 初始化上下文
        DutyScheduleContext context = initScheduleContext(dudyScheduleSetSaveVO, sMonth, sYear, endYear, endMonth);
        dutyScheduleInfos = getParents(dutyScheduleInfos);
        
        // 科员工作日班
        generateScheduleForSectionLevel(context, "3", "1", YBList, true, dutyPersonInitDetailVOS,
                dutyScheduleInfos, dutyScheduleGroupRecords,
                (i, scheduleList, dudyTemplates, deptTemplates, persons, dutyPersonInitVO) -> {
                    DutyScheduleSet temp = getDayOfYBList(i, scheduleList, dudyTemplates, null, dutyPersonInitVO,
                            persons, context.getAllDepts(), context.getBaseDeptInfos(), deptTemplates);
                    return getDetailDay(context.getSYear(), context.getSMonth(), i, context.getHolidays(),
                            context.getImportantDays(), context.getCustom(), context.getExchangeDays(),
                            dudyTemplates, scheduleList, context.getAllDepts(), context.getBaseDeptInfos(),
                            deptTemplates, persons, dutyPersonInitVO);
                });
        // 科员周末班
        generateScheduleForSectionLevel(context, "3", "4", ZMList, true, dutyPersonInitDetailVOS,
                dutyScheduleInfos, dutyScheduleGroupRecords,
                (i, scheduleList, dudyTemplates, deptTemplates, persons, dutyPersonInitVO) -> {
                    DutyScheduleSet temp = getDayOfYBList(i, scheduleList, dudyTemplates, null, dutyPersonInitVO,
                            persons, context.getAllDepts(), context.getBaseDeptInfos(), deptTemplates);
                    return getWeekendDay(context.getSYear(), context.getSMonth(), i, context.getHolidays(),
                            context.getImportantDays(), context.getCustom(), context.getExchangeDays(),
                            dudyTemplates, scheduleList, context.getAllDepts(), context.getBaseDeptInfos(),
                            deptTemplates, persons, dutyPersonInitVO);
                });
        // 科员节假日班
        generateScheduleForSectionLevel(context, "3", "2", ZMBList, true, dutyPersonInitDetailVOS,
                dutyScheduleInfos, dutyScheduleGroupRecords,
                (i, scheduleList, dudyTemplates, deptTemplates, persons, dutyPersonInitVO) -> {
                    DutyScheduleSet temp = getDayOfYBList(i, scheduleList, dudyTemplates, null, dutyPersonInitVO,
                            persons, context.getAllDepts(), context.getBaseDeptInfos(), deptTemplates);
                    return getHoilday(context.getSYear(), context.getSMonth(), i, context.getHolidays(),
                            context.getImportantDays(), context.getCustom(), context.getExchangeDays(),
                            dudyTemplates, scheduleList, context.getAllDepts(), context.getBaseDeptInfos(),
                            deptTemplates, persons, dutyPersonInitVO);
                });
        // 科员重要班
        generateScheduleForSectionLevel(context, "3", "3", ZYBList, true, dutyPersonInitDetailVOS,
                dutyScheduleInfos, dutyScheduleGroupRecords,
                (i, scheduleList, dudyTemplates, deptTemplates, persons, dutyPersonInitVO) -> {
                    DutyScheduleSet temp = getDayOfYBList(i, scheduleList, dudyTemplates, null, dutyPersonInitVO,
                            persons, context.getAllDepts(), context.getBaseDeptInfos(), deptTemplates);
                    return getImportDay(context.getSYear(), context.getSMonth(), i, context.getHolidays(),
                            context.getImportantDays(), context.getCustom(), context.getExchangeDays(),
                            dudyTemplates, scheduleList, context.getAllDepts(), context.getBaseDeptInfos(),
                            deptTemplates, persons, dutyPersonInitVO);
                });
        // 处级工作日班
        generateScheduleForDivisionLevel(context, "2", "1", YBList, dutyPersonInitDetailVOS,
                dutyScheduleInfos, dutyScheduleGroupRecords,
                (i, scheduleList, dudyTemplates, deptTemplates, persons, dutyPersonInitVO) -> {
                    DutyScheduleSet temp = getDayOfYBListForD(i, scheduleList, dudyTemplates, null, dutyPersonInitVO,
                            persons, context.getAllDepts(), context.getBaseDeptInfos(), deptTemplates);
                    return getDetailDayForD(context.getSYear(), context.getSMonth(), i, context.getHolidays(),
                            context.getImportantDays(), context.getCustom(), context.getExchangeDays(),
                            dudyTemplates, scheduleList, context.getAllDepts(), context.getBaseDeptInfos(),
                            deptTemplates, persons, dutyPersonInitVO);
                });
        // 处级周末班
        generateScheduleForDivisionLevel(context, "2", "4", ZMList, dutyPersonInitDetailVOS,
                dutyScheduleInfos, dutyScheduleGroupRecords,
                (i, scheduleList, dudyTemplates, deptTemplates, persons, dutyPersonInitVO) -> {
                    DutyScheduleSet temp = getDayOfYBListForD(i, scheduleList, dudyTemplates, null, dutyPersonInitVO,
                            persons, context.getAllDepts(), context.getBaseDeptInfos(), deptTemplates);
                    return getWeekendDayForDay(context.getSYear(), context.getSMonth(), i, context.getHolidays(),
                            context.getImportantDays(), context.getCustom(), context.getExchangeDays(),
                            dudyTemplates, scheduleList, context.getAllDepts(), context.getBaseDeptInfos(),
                            deptTemplates, persons, dutyPersonInitVO);
                });
        // 处级节假日班
        generateScheduleForDivisionLevel(context, "2", "2", ZMBList, dutyPersonInitDetailVOS,
                dutyScheduleInfos, dutyScheduleGroupRecords,
                (i, scheduleList, dudyTemplates, deptTemplates, persons, dutyPersonInitVO) -> {
                    DutyScheduleSet temp = getDayOfYBListForD(i, scheduleList, dudyTemplates, null, dutyPersonInitVO,
                            persons, context.getAllDepts(), context.getBaseDeptInfos(), deptTemplates);
                    return getHoildayForD(context.getSYear(), context.getSMonth(), i, context.getHolidays(),
                            context.getImportantDays(), context.getCustom(), context.getExchangeDays(),
                            dudyTemplates, scheduleList, context.getAllDepts(), context.getBaseDeptInfos(),
                            deptTemplates, persons, dutyPersonInitVO);
                });
        // 处级重要班
        generateScheduleForDivisionLevel(context, "2", "3", ZYBList, dutyPersonInitDetailVOS,
                dutyScheduleInfos, dutyScheduleGroupRecords,
                (i, scheduleList, dudyTemplates, deptTemplates, persons, dutyPersonInitVO) -> {
                    DutyScheduleSet temp = getDayOfYBListForD(i, scheduleList, dudyTemplates, null, dutyPersonInitVO,
                            persons, context.getAllDepts(), context.getBaseDeptInfos(), deptTemplates);
                    return getImportDayForD(context.getSYear(), context.getSMonth(), i, context.getHolidays(),
                            context.getImportantDays(), context.getCustom(), context.getExchangeDays(),
                            dudyTemplates, scheduleList, context.getAllDepts(), context.getBaseDeptInfos(),
                            deptTemplates, persons, dutyPersonInitVO);
                });
        // 计算关领导级别的日期数量
        List<ParamScheduleSetting> rcSetting = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, dudyScheduleSetSaveVO.getCustomId())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_RC.getValue()));
        List<ParamScheduleSetting> zmbSetting = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, dudyScheduleSetSaveVO.getCustomId())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_ZMB.getValue()));
        List<ParamScheduleSetting> zybSetting = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, dudyScheduleSetSaveVO.getCustomId())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_ZYB.getValue()));
        List<ParamScheduleSetting> zmSetting = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, dudyScheduleSetSaveVO.getCustomId())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_ZM.getValue()));

        Integer hoilDayCount = context.getHolidays().size() * zmbSetting.size();
        Integer importantCount = context.getImportantDays().size() * zybSetting.size();
        Integer commonCount = DateUtil.getCommonCount(context.getSYear(), context.getSMonth(), context.getEndYear(), context.getEndMonth(),
                context.getHolidays(), context.getImportantDays(), context.getExchangeDays(), rcSetting, zmSetting);
        Integer weekendCount = DateUtil.getWeekendCount(context.getSYear(), context.getSMonth(), context.getEndYear(), context.getEndMonth(),
                context.getHolidays(), context.getImportantDays(), context.getExchangeDays(), rcSetting, zmSetting);

        // 关领导工作日班
        generateScheduleForLeaderLevel(context, "1", "1", YBList, commonCount, dutyPersonInitDetailVOS,
                dutyScheduleInfos, dutyScheduleGroupRecords,
                (i, scheduleList, dudyTemplates, deptTemplates, persons, dutyPersonInitVO) ->
                        getDetailDayForG(context.getSYear(), context.getSMonth(), i, context.getHolidays(),
                                context.getImportantDays(), context.getCustom(), context.getExchangeDays(),
                                null, scheduleList, context.getAllDepts(), context.getBaseDeptInfos(),
                                deptTemplates, persons, dutyPersonInitVO));
        // 关领导周末班
        generateScheduleForLeaderLevel(context, "1", "4", YBList, weekendCount, dutyPersonInitDetailVOS,
                dutyScheduleInfos, dutyScheduleGroupRecords,
                (i, scheduleList, dudyTemplates, deptTemplates, persons, dutyPersonInitVO) ->
                        getWeekendDayForG(context.getSYear(), context.getSMonth(), i, context.getHolidays(),
                                context.getImportantDays(), context.getCustom(), context.getExchangeDays(),
                                null, scheduleList, context.getAllDepts(), context.getBaseDeptInfos(),
                                deptTemplates, persons, dutyPersonInitVO));
        // 关领导节假日班
        generateScheduleForLeaderLevel(context, "1", "2", YBList, hoilDayCount, dutyPersonInitDetailVOS,
                dutyScheduleInfos, dutyScheduleGroupRecords,
                (i, scheduleList, dudyTemplates, deptTemplates, persons, dutyPersonInitVO) ->
                        getHoildayForG(context.getSYear(), context.getSMonth(), i, context.getHolidays(),
                                context.getImportantDays(), context.getCustom(), context.getExchangeDays(),
                                null, scheduleList, context.getAllDepts(), context.getBaseDeptInfos(),
                                deptTemplates, persons, dutyPersonInitVO));
        // 关领导重要班
        generateScheduleForLeaderLevel(context, "1", "3", YBList, importantCount, dutyPersonInitDetailVOS,
                dutyScheduleInfos, dutyScheduleGroupRecords,
                (i, scheduleList, dudyTemplates, deptTemplates, persons, dutyPersonInitVO) ->
                        getImportDayForG(context.getSYear(), context.getSMonth(), i, context.getHolidays(),
                                context.getImportantDays(), context.getCustom(), context.getExchangeDays(),
                                null, scheduleList, context.getAllDepts(), context.getBaseDeptInfos(),
                                deptTemplates, persons, dutyPersonInitVO));
        //周末版 关领导,处领导，科领导
        //节假日版 关领导,处领导，科领导

        //重要时期班版 关领导,处领导，科领导
        List<ParamDuty> ditys = paramDutyRepository.list(new LambdaQueryWrapper<ParamDuty>()
                .eq(ParamDuty::getDDept, context.getCustom().getId()));
        Map<String, ParamDuty> paramDutyMap = ditys.stream().collect(Collectors.toMap(i -> i.getId(), i -> i));
        Map<String, BaseDeptInfo> baseDeptInfoMap = context.getAllDepts().stream().collect(Collectors.toMap(i -> i.getId(), i -> i));
        dutyScheduleInfos = dutyScheduleInfos.stream().map(j -> {
            DutyScheduleInfo i = new DutyScheduleInfo();
            BeanUtils.copyProperties(j, i);
            i.setId(null);
            i.setSetCustomId(id);
            i.setCreateTime(LocalDateTime.now());
            i.setUpdateTime(LocalDateTime.now());
            i.setCreateBy("-1");
            i.setUpdateBy("-1");
            i.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
            if (i.getDDeptname() == null && !StringUtils.isEmpty(i.getDDept())) {
                BaseDeptInfo baseDeptInfo = baseDeptInfoMap.get(i.getDDept());
                if (baseDeptInfo != null) {
                    i.setDDeptname(baseDeptInfo.getDeptName()
                    );
                }
            }
            i.setCustomId(context.getCustom().getId());
            i.setCustomName(context.getCustom().getDeptName());
            ParamDuty paramDuty = paramDutyMap.get(i.getDutyTimesId());
            if (paramDuty != null&&!StringUtils.isEmpty(paramDuty.getId())) {
                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                    i.setDStartDateTime(i.getDDay().atTime(paramDuty.getDStartTime()));
                    i.setDEndDateTime(i.getDDay().atTime(paramDuty.getDEndTime()));
                } else {
                    i.setDStartDateTime(i.getDDay().atTime(paramDuty.getDStartTime()));
                    i.setDEndDateTime(i.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                }
            }
//            switch (i.getDUserjob()){
//                case "1":
//                    i.setDutyType("7");
//                    break;
//                case "2":
//                    i.setDutyType("6");
//            }
            return i;

        }).collect(Collectors.toList());
        dutyScheduleInfoRepository.saveBatch(dutyScheduleInfos);
        List<DutySignInfo> dutySignInfos = new ArrayList<>();
        for (DutyScheduleInfo scheduleInfo : dutyScheduleInfos) {
            if (!org.apache.commons.lang.StringUtils.isEmpty(scheduleInfo.getDUserno())) {
                DutySignInfo dutySignInfo = new DutySignInfo();
                dutySignInfo.setDId(scheduleInfo.getId());
                dutySignInfo.setCreateBy("sys");
                dutySignInfo.setCreateTime(LocalDateTime.now());
                dutySignInfo.setUpdateBy("sys");
                dutySignInfo.setUpdateTime(LocalDateTime.now());
                dutySignInfo.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
                dutySignInfos.add(dutySignInfo);
            }
        }
        if (!CollectionUtils.isEmpty(dutySignInfos)) {
            dutySignInfoRepository.saveBatch(dutySignInfos);
        }
//        if (!isReinit) {
//            List<DutyScheduleSetCustomRecord> allRecords = new ArrayList<>();
//            allRecords.addAll(dailyRecords);
//            allRecords.addAll(hoildayRecords);
//            allRecords.addAll(importDayRecords);
//            allRecords.addAll(hoildayCJRecords);
//            allRecords.addAll(importDayCJRecords);
//            dutyScheduleSetCustomRecordRepository.remove(new LambdaQueryWrapper<DutyScheduleSetCustomRecord>()
//                    .eq(DutyScheduleSetCustomRecord::getCustomId, custom.getId()));
//            dutyScheduleSetCustomRecordRepository.saveBatch(allRecords);
//        }
    }

    private List<DutyScheduleInfo> getParents(List<DutyScheduleInfo> dutyScheduleInfos) {
        List<BaseDeptInfo> deptInfoList = guavacacheUtils.getDepts();
        Map<String, BaseDeptInfo> deptInfoMap = deptInfoList.stream().collect(Collectors.toMap(BaseDeptInfo::getId, i -> i));
        for (DutyScheduleInfo dutyScheduleInfo : dutyScheduleInfos) {
            BaseDeptInfo baseDeptInfo = deptInfoMap.get(dutyScheduleInfo.getDDept());
            if (baseDeptInfo != null) {
                BaseDeptInfo parent = deptInfoMap.get(baseDeptInfo.getParentid());
                if (parent != null && !systemConfig.getZsCustomName().equals(parent.getDeptName())) {
                    dutyScheduleInfo.setDDeptname(dutyScheduleInfo.getDDeptname() + "(" + parent.getDeptName() + ")");
                    dutyScheduleInfo.setDDept(parent.getId());
                }
            }
            if ("科员".equals(dutyScheduleInfo.getDUserjob()) || "科领导".equals(dutyScheduleInfo.getDUserjob())) {
                dutyScheduleInfo.setDType("1");
            } else if ("处领导".equals(dutyScheduleInfo.getDUserjob()) || "关领导".equals(dutyScheduleInfo.getDUserjob())) {
                dutyScheduleInfo.setDType("2");
            }
        }
        return dutyScheduleInfos;
    }

//    private DutyScheduleSet getDayOfZMBSType(int commonCount, List<DutyScheduleSet> zmbs, List<DudyScheduleListVO.DudyTemplate> lineTemplate, List<DudyScheduleListVO.DudyTemplate> holidayTemplates) {
//        lineTemplate=createLineTemplates(zmbs,lineTemplate, dutyPersonInitVO);
//        long flag=0;
//        for (DudyScheduleListVO.DudyTemplate dudyTemplate:lineTemplate){
//            flag+=dudyTemplate.getSectionLevelDudyNumber();
//            if (commonCount<=flag){
//                DutyScheduleSet dutyScheduleSet=zmbs.stream().filter(i->i.getDeptId().equals(dudyTemplate.getDudyDeptId()))
//                        .max(Comparator.comparing(i->i.getId())).orElse(null);
//                return dutyScheduleSet;
//            }
//        }
//        return null;
//    }


    private String getDupostByH4a(String rankCode) {
        String result = "";
        if (rankCode == null) {
            return result;
        }
        switch (rankCode) {
            case "05":
                result = "厅局级正职";
                break;
            case "06":
                result = "厅局级副职";
                break;
            case "07":
                result = "县处级正职";
                break;
            case "08":
                result = "县处级副职";
                break;
            case "09":
                result = "乡科级正职";
                break;
            case "10":
                result = "乡科级副职";
                break;
            case "11":
                result = "科员";
                break;
            case "99":
                result = "无行政级别";
                break;
            default:
                return "其他";
        }
        return result;
    }

    private List<DutyScheduleInfo> getDetailDay(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                List<ParamHolidays> importantDays,
                                                BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListVO.DudyTemplate> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_RC.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleSet temp = getDayOfYBList(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("1");
                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                dutyScheduleInfo.setDDept(temp.getDeptId());
                                BasePersonInfo basePersonInfo = getDailyPerson(a, dudyTemplates);
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("科员");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.DIRECTLY_SECTION_MEMBER.getValue());
                                dutyScheduleInfo.setDType("1");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        } else {
                            index = index.plusDays(1);
                            flag--;
                            continue;
                        }
                    default:
                        if (i % paramScheduleSettingList.size() != 0) {
                            continue;
                        }
                        int a = i - paramScheduleSettingList.size() + 1;
                        for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                            DutyScheduleSet temp = getDayOfYBList(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                            DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                            dutyScheduleInfo.setSId(temp.getId());
                            dutyScheduleInfo.setSType("1");
                            dutyScheduleInfo.setDDeptname(temp.getDeptName());
                            dutyScheduleInfo.setDDept(temp.getDeptId());
                            BasePersonInfo basePersonInfo = getDailyPerson(a, dudyTemplates);
                            a++;
                            dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                            dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                            dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                            dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                            dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                            dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                            dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                            dutyScheduleInfo.setDDay(index);
                            dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                            dutyScheduleInfo.setDUserjob("科员");
                            dutyScheduleInfo.setDutyType(DutyTypeEnum.DIRECTLY_SECTION_MEMBER.getValue());
                            dutyScheduleInfo.setDType("1");
                            ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                            DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                            dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                            if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                            } else {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                            }
                            dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                            result.add(dutyScheduleInfo);
                        }
                        return result;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    } else {
                        flag--;
                        index = index.plusDays(1);
                    }
                    break;
                default:
                    if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {
                        index = index.plusDays(1);
                        usedFlag += paramScheduleSettingList.size();
                    }
                    break;
            }


        }
        return result;
    }

    private List<DutyScheduleInfo> getDetailDayForZST(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                      List<ParamHolidays> importantDays,
                                                      BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_RC.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleSet temp = getDayOfYBListForZST(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("1");
                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                dutyScheduleInfo.setDDept(temp.getDeptId());
                                BasePersonInfo basePersonInfo = getDailyPersonForZST(a, dudyTemplates);
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("司局领导");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.DEPARTMENT_EXCHANGE.getValue());
                                dutyScheduleInfo.setDType("2");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        } else {
                            index = index.plusDays(1);
                            flag--;
                            continue;
                        }
                    default:
                        if (i % paramScheduleSettingList.size() != 0) {
                            continue;
                        }
                        int a = i - paramScheduleSettingList.size() + 1;
                        for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                            DutyScheduleSet temp = getDayOfYBListForZST(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                            DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                            dutyScheduleInfo.setSId(temp.getId());
                            dutyScheduleInfo.setSType("1");
                            dutyScheduleInfo.setDDeptname(temp.getDeptName());
                            dutyScheduleInfo.setDDept(temp.getDeptId());
                            BasePersonInfo basePersonInfo = getDailyPersonForZST(a, dudyTemplates);
                            a++;
                            dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                            dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                            dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                            dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                            dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                            dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                            dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                            dutyScheduleInfo.setDDay(index);
                            dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                            dutyScheduleInfo.setDUserjob("司局领导");
                            dutyScheduleInfo.setDutyType(DutyTypeEnum.DEPARTMENT_EXCHANGE.getValue());
                            dutyScheduleInfo.setDType("2");
                            ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                            DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                            dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                            if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                            } else {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                            }
                            dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                            result.add(dutyScheduleInfo);
                        }
                        return result;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    } else {
                        flag--;
                        index = index.plusDays(1);
                    }
                    break;
                default:
                    if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {
                        index = index.plusDays(1);
                        usedFlag += paramScheduleSettingList.size();
                    }
                    break;
            }


        }
        return result;
    }

    private List<DutyScheduleInfo> getDetailDayForZSC(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                      List<ParamHolidays> importantDays,
                                                      BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_RC.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleSet temp = getDayOfYBListForZSC(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("1");
                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                dutyScheduleInfo.setDDept(temp.getDeptId());
                                BasePersonInfo basePersonInfo = getDailyPersonForZSC(a, dudyTemplates);
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("处领导");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.DIVISION_LEADER.getValue());
                                dutyScheduleInfo.setDType("2");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        } else {
                            index = index.plusDays(1);
                            flag--;
                            continue;
                        }
                    default:
                        if (i % paramScheduleSettingList.size() != 0) {
                            continue;
                        }
                        int a = i - paramScheduleSettingList.size() + 1;
                        for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                            DutyScheduleSet temp = getDayOfYBListForZSC(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                            DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                            dutyScheduleInfo.setSId(temp.getId());
                            dutyScheduleInfo.setSType("1");
                            dutyScheduleInfo.setDDeptname(temp.getDeptName());
                            dutyScheduleInfo.setDDept(temp.getDeptId());
                            BasePersonInfo basePersonInfo = getDailyPersonForZSC(a, dudyTemplates);
                            a++;
                            dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                            dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                            dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                            dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                            dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                            dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                            dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                            dutyScheduleInfo.setDDay(index);
                            dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                            dutyScheduleInfo.setDUserjob("处领导");
                            dutyScheduleInfo.setDutyType(DutyTypeEnum.DIVISION_LEADER.getValue());
                            dutyScheduleInfo.setDType("2");
                            ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                            DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                            dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                            if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                            } else {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                            }
                            dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                            result.add(dutyScheduleInfo);
                        }
                        return result;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    } else {
                        flag--;
                        index = index.plusDays(1);
                    }
                    break;
                default:
                    if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {
                        index = index.plusDays(1);
                        usedFlag += paramScheduleSettingList.size();
                    }
                    break;
            }


        }
        return result;
    }

    private List<DutyScheduleInfo> getDetailDayForZSMain(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                         List<ParamHolidays> importantDays,
                                                         BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_RC.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleSet temp = getDayOfYBListForZSMain(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("1");
                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                dutyScheduleInfo.setDDept(temp.getDeptId());
                                BasePersonInfo basePersonInfo = getDailyPersonForZSMain(a, dudyTemplates);
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("主值班员");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.MASTER_DUTY.getValue());
                                dutyScheduleInfo.setDType("1");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        } else {
                            index = index.plusDays(1);
                            flag--;
                            continue;
                        }
                    default:
                        if (i % paramScheduleSettingList.size() != 0) {
                            continue;
                        }
                        int a = i - paramScheduleSettingList.size() + 1;
                        for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                            DutyScheduleSet temp = getDayOfYBListForZSMain(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                            DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                            dutyScheduleInfo.setSId(temp.getId());
                            dutyScheduleInfo.setSType("1");
                            dutyScheduleInfo.setDDeptname(temp.getDeptName());
                            dutyScheduleInfo.setDDept(temp.getDeptId());
                            BasePersonInfo basePersonInfo = getDailyPersonForZSMain(a, dudyTemplates);
                            a++;
                            dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                            dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                            dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                            dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                            dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                            dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                            dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                            dutyScheduleInfo.setDDay(index);
                            dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                            dutyScheduleInfo.setDUserjob("主值班员");
                            dutyScheduleInfo.setDutyType(DutyTypeEnum.MASTER_DUTY.getValue());
                            dutyScheduleInfo.setDType("1");
                            ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                            DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                            dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                            if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                            } else {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                            }
                            dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                            result.add(dutyScheduleInfo);
                        }
                        return result;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    } else {
                        flag--;
                        index = index.plusDays(1);
                    }
                    break;
                default:
                    if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {
                        index = index.plusDays(1);
                        usedFlag += paramScheduleSettingList.size();
                    }
                    break;
            }


        }
        return result;
    }

    private List<DutyScheduleInfo> getDetailDayForZSSub(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                        List<ParamHolidays> importantDays,
                                                        BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_RC.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleSet temp = getDayOfYBListForZSSub(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("1");
                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                dutyScheduleInfo.setDDept(temp.getDeptId());
                                BasePersonInfo basePersonInfo = getDailyPersonForZSSub(a, dudyTemplates);
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("副值班员");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.DEPUTY_DUTY.getValue());
                                dutyScheduleInfo.setDType("1");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        } else {
                            index = index.plusDays(1);
                            flag--;
                            continue;
                        }
                    default:
                        if (i % paramScheduleSettingList.size() != 0) {
                            continue;
                        }
                        int a = i - paramScheduleSettingList.size() + 1;
                        for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                            DutyScheduleSet temp = getDayOfYBListForZSSub(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                            DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                            dutyScheduleInfo.setSId(temp.getId());
                            dutyScheduleInfo.setSType("1");
                            dutyScheduleInfo.setDDeptname(temp.getDeptName());
                            dutyScheduleInfo.setDDept(temp.getDeptId());
                            BasePersonInfo basePersonInfo = getDailyPersonForZSSub(a, dudyTemplates);
                            a++;
                            dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                            dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                            dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                            dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                            dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                            dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                            dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                            dutyScheduleInfo.setDDay(index);
                            dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                            dutyScheduleInfo.setDUserjob("副值班员");
                            dutyScheduleInfo.setDutyType(DutyTypeEnum.DEPUTY_DUTY.getValue());
                            dutyScheduleInfo.setDType("1");
                            ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                            DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                            dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                            if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                            } else {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                            }
                            dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                            result.add(dutyScheduleInfo);
                        }
                        return result;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    } else {
                        flag--;
                        index = index.plusDays(1);
                    }
                    break;
                default:
                    if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {
                        index = index.plusDays(1);
                        usedFlag += paramScheduleSettingList.size();
                    }
                    break;
            }


        }
        return result;
    }


    private List<DutyScheduleInfo> getDetailDayForZSS(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                      List<ParamHolidays> importantDays,
                                                      BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(),
                SetDutyTypeEnum.TYPE_RC.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleSet temp = getDayOfYBListForZSS(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("1");
                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                dutyScheduleInfo.setDDept(temp.getDeptId());
                                BasePersonInfo basePersonInfo = getDailyPersonForZSS(a, dudyTemplates);
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("署领导");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.GENERAL_ADMINISTRATION_LEADER.getValue());
                                dutyScheduleInfo.setDType("2");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        } else {
                            index = index.plusDays(1);
                            flag--;
                            continue;
                        }
                    default:
                        if (i % paramScheduleSettingList.size() != 0) {
                            continue;
                        }
                        int a = i - paramScheduleSettingList.size() + 1;
                        for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                            DutyScheduleSet temp = getDayOfYBListForZSS(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                            DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                            dutyScheduleInfo.setSId(temp.getId());
                            dutyScheduleInfo.setSType("1");
                            dutyScheduleInfo.setDDeptname(temp.getDeptName());
                            dutyScheduleInfo.setDDept(temp.getDeptId());
                            BasePersonInfo basePersonInfo = getDailyPersonForZSS(a, dudyTemplates);
                            a++;
                            dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                            dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                            dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                            dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                            dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                            dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                            dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                            dutyScheduleInfo.setDDay(index);
                            dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                            dutyScheduleInfo.setDUserjob("署领导");
                            dutyScheduleInfo.setDutyType(DutyTypeEnum.GENERAL_ADMINISTRATION_LEADER.getValue());
                            dutyScheduleInfo.setDType("2");
                            ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                            DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                            dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                            if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                            } else {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                            }
                            dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                            result.add(dutyScheduleInfo);
                        }
                        return result;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    } else {
                        flag--;
                        index = index.plusDays(1);
                    }
                    break;
                default:
                    if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {
                        index = index.plusDays(1);
                        usedFlag += paramScheduleSettingList.size();
                    }
                    break;
            }


        }
        return result;
    }

    private List<DutyScheduleInfo> getDetailDayForD(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                    List<ParamHolidays> importantDays,
                                                    BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListVO.DudyTemplate> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_RC.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleSet temp = getDayOfYBListForD(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("1");
                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                dutyScheduleInfo.setDDept(temp.getDeptId());
                                BasePersonInfo basePersonInfo = getDailyPersonForD(a, dudyTemplates);
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("处领导");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.DIRECTLY_DIVISION_LEADER.getValue());
                                dutyScheduleInfo.setDType("2");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        } else {
                            index = index.plusDays(1);
                            flag--;
                            continue;
                        }
                    default:
                        if (i % paramScheduleSettingList.size() != 0) {
                            continue;
                        }
                        int a = i - paramScheduleSettingList.size() + 1;
                        for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                            DutyScheduleSet temp = getDayOfYBListForD(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                            DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                            dutyScheduleInfo.setSId(temp.getId());
                            dutyScheduleInfo.setSType("1");
                            dutyScheduleInfo.setDDeptname(temp.getDeptName());
                            dutyScheduleInfo.setDDept(temp.getDeptId());
                            BasePersonInfo basePersonInfo = getDailyPersonForD(a, dudyTemplates);
                            a++;
                            dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                            dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                            dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                            dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                            dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                            dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                            dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                            dutyScheduleInfo.setDDay(index);
                            dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                            dutyScheduleInfo.setDUserjob("处领导");
                            dutyScheduleInfo.setDutyType(DutyTypeEnum.DIRECTLY_DIVISION_LEADER.getValue());
                            dutyScheduleInfo.setDType("2");
                            ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                            DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                            dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                            if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                            } else {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                            }
                            dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                            result.add(dutyScheduleInfo);
                        }
                        return result;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    } else {
                        flag--;
                        index = index.plusDays(1);
                    }
                    break;
                default:
                    if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {
                        index = index.plusDays(1);
                        usedFlag += paramScheduleSettingList.size();
                    }
                    break;
            }


        }
        return result;
    }

    private List<DutyScheduleInfo> getDetailDayForG(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                    List<ParamHolidays> importantDays,
                                                    BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListVO.DudyTemplate> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_RC.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
//                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("1");
//                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                BasePersonInfo basePersonInfo = getDailyPersonForG(a, persons, dutyPersonInitVO);
                                dutyScheduleInfo.setDDept(basePersonInfo.getDeptId());
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("关领导");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.DIRECTLY_CUSTOMS_LEADER.getValue());
                                dutyScheduleInfo.setDType("2");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        } else {
                            continue;
                        }
                    default:
                        if (i % paramScheduleSettingList.size() != 0) {
                            continue;
                        }
                        int a = i - paramScheduleSettingList.size() + 1;
                        for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                            DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
//                                dutyScheduleInfo.setSId(temp.getId());
                            dutyScheduleInfo.setSType("1");
//                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                            BasePersonInfo basePersonInfo = getDailyPersonForG(a, persons, dutyPersonInitVO);
                            dutyScheduleInfo.setDDept(basePersonInfo.getDeptId());
                            a++;
                            dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                            dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                            dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                            dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                            dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                            dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                            dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                            dutyScheduleInfo.setDDay(index);
                            dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                            dutyScheduleInfo.setDUserjob("关领导");
                            dutyScheduleInfo.setDutyType(DutyTypeEnum.DIRECTLY_CUSTOMS_LEADER.getValue());
                            dutyScheduleInfo.setDType("2");
                            ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                            DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                            dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                            if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                            } else {
                                dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                            }
                            dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                            result.add(dutyScheduleInfo);
                        }
                        return result;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    } else {
                        flag--;
                        index = index.plusDays(1);
                    }
                    break;
                default:
                    if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {
                        index = index.plusDays(1);
                        usedFlag += paramScheduleSettingList.size();
                    }
                    break;
            }


        }
        return result;
    }

    private BasePersonInfo getDailyPersonForG(int a, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        int flag = 0;
        for (int i = 0; i < persons.size(); i++) {
            if (persons.get(i).getUserno().equals(dutyPersonInitVO.getPersonNo())) {
                flag = i;
            }
        }
        List<BasePersonInfo> sortedLsit = new ArrayList<>();
        sortedLsit.addAll(persons.subList(flag, persons.size()));
        sortedLsit.addAll(persons.subList(0, flag));
        flag = 0;
        flag = a % persons.size();
        BasePersonInfo dudyTemplate = persons.get(flag);
        return dudyTemplate;
    }

    private List<DutyScheduleInfo> getWeekendDay(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                 List<ParamHolidays> importantDays,
                                                 BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListVO.DudyTemplate> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZM.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) || i % paramScheduleSettingList.size() != 0) {

                        } else {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleSet temp = getDayOfYBList(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("4");
                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                dutyScheduleInfo.setDDept(temp.getDeptId());
                                BasePersonInfo basePersonInfo = getDailyPerson(a, dudyTemplates);
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("科员");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.DIRECTLY_SECTION_MEMBER.getValue());
                                dutyScheduleInfo.setDType("1");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        }
                    default:
                        if (paramScheduleSettingList.size() ==1) {
                            flag--;
                            index = index.plusDays(1);
                        }
                        continue;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        flag--;
                        index = index.plusDays(1);
                    } else {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {
                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    }
                    break;
                default:
                    flag--;
                    index = index.plusDays(1);
                    break;
            }
        }
        return result;
    }

    private List<DutyScheduleInfo> getWeekendDayForZSS(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                       List<ParamHolidays> importantDays,
                                                       BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZM.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) || i % paramScheduleSettingList.size() != 0) {

                        } else {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleSet temp = getDayOfYBListForZSS(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("4");
                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                dutyScheduleInfo.setDDept(temp.getDeptId());
                                BasePersonInfo basePersonInfo = getDailyPersonForZSS(a, dudyTemplates);
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("署领导");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.GENERAL_ADMINISTRATION_LEADER.getValue());
                                dutyScheduleInfo.setDType("2");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        }
                    default:


                        continue;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        flag--;
                        index = index.plusDays(1);
                    } else {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {
                            if (paramScheduleSettingList.size() == 1) {
                                flag--;
                            }
                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    }
                    break;
                default:
                    flag--;
                    index = index.plusDays(1);
                    break;
            }
        }
        return result;
    }


    private List<DutyScheduleInfo> getWeekendDayForZST(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                       List<ParamHolidays> importantDays,
                                                       BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZM.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) || i % paramScheduleSettingList.size() != 0) {

                        } else {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleSet temp = getDayOfYBListForZST(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("4");
                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                dutyScheduleInfo.setDDept(temp.getDeptId());
                                BasePersonInfo basePersonInfo = getDailyPersonForZST(a, dudyTemplates);
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("司局领导");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.DEPARTMENT_EXCHANGE.getValue());
                                dutyScheduleInfo.setDType("2");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        }
                    default:
                        if (paramScheduleSettingList.size() ==1) {
                            flag--;
                            index = index.plusDays(1);
                        }
                        continue;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        flag--;
                        index = index.plusDays(1);
                    } else {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {
                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    }
                    break;
                default:
                    flag--;
                    index = index.plusDays(1);
                    break;
            }
        }
        return result;
    }

    private List<DutyScheduleInfo> getWeekendDayForZSC(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                       List<ParamHolidays> importantDays,
                                                       BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZM.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) || i % paramScheduleSettingList.size() != 0) {

                        } else {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleSet temp = getDayOfYBListForZSC(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("4");
                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                dutyScheduleInfo.setDDept(temp.getDeptId());
                                BasePersonInfo basePersonInfo = getDailyPersonForZSC(a, dudyTemplates);
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("处领导");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.DIVISION_LEADER.getValue());
                                dutyScheduleInfo.setDType("2");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        }
                    default:
                        if (paramScheduleSettingList.size() ==1) {
                            flag--;
                            index = index.plusDays(1);
                        }
                        continue;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        flag--;
                        index = index.plusDays(1);
                    } else {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {
                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    }
                    break;
                default:
                    flag--;
                    index = index.plusDays(1);
                    break;
            }
        }
        return result;
    }

    private List<DutyScheduleInfo> getWeekendDayForZSMain(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                          List<ParamHolidays> importantDays,
                                                          BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZM.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) || i % paramScheduleSettingList.size() != 0) {

                        } else {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleSet temp = getDayOfYBListForZSMain(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("4");
                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                dutyScheduleInfo.setDDept(temp.getDeptId());
                                BasePersonInfo basePersonInfo = getDailyPersonForZSMain(a, dudyTemplates);
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("主值班员");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.MASTER_DUTY.getValue());
                                dutyScheduleInfo.setDType("1");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        }
                    default:
                        if (paramScheduleSettingList.size() ==1) {
                            flag--;
                            index = index.plusDays(1);
                        }
                        continue;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        flag--;
                        index = index.plusDays(1);
                    } else {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    }
                    break;
                default:
                    flag--;
                    index = index.plusDays(1);
                    break;
            }
        }
        return result;
    }

    private List<DutyScheduleInfo> getWeekendDayForZSSub(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                         List<ParamHolidays> importantDays,
                                                         BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZM.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) || i % paramScheduleSettingList.size() != 0) {

                        } else {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleSet temp = getDayOfYBListForZSSub(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("4");
                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                dutyScheduleInfo.setDDept(temp.getDeptId());
                                BasePersonInfo basePersonInfo = getDailyPersonForZSSub(a, dudyTemplates);
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("副值班员");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.DEPUTY_DUTY.getValue());
                                dutyScheduleInfo.setDType("1");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        }
                    default:
                        if (paramScheduleSettingList.size() ==1) {
                            flag--;
                            index = index.plusDays(1);
                        }
                        continue;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        flag--;
                        index = index.plusDays(1);
                    } else {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    }
                    break;
                default:
                    flag--;
                    index = index.plusDays(1);
                    break;
            }
        }
        return result;
    }

    private List<DutyScheduleInfo> getWeekendDayForG(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                     List<ParamHolidays> importantDays,
                                                     BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListVO.DudyTemplate> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZM.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) || i % paramScheduleSettingList.size() != 0) {

                        } else {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
//                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("4");
//                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                BasePersonInfo basePersonInfo = getDailyPersonForG(a, persons, dutyPersonInitVO);
                                dutyScheduleInfo.setDDept(basePersonInfo.getDeptId());
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("关领导");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.DIRECTLY_CUSTOMS_LEADER.getValue());
                                dutyScheduleInfo.setDType("2");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        }
                    default:
                        if (paramScheduleSettingList.size() ==1) {
                            flag--;
                            index = index.plusDays(1);
                        }
                        continue;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        flag--;
                        index = index.plusDays(1);
                    } else {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    }
                    break;
                default:
                    flag--;
                    index = index.plusDays(1);
                    break;
            }
        }
        return result;
    }


    private List<DutyScheduleInfo> getWeekendDayForDay(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                       List<ParamHolidays> importantDays,
                                                       BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListVO.DudyTemplate> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZM.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index) || importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
                switch (day) {
                    case SATURDAY:
                    case SUNDAY:
                        if (exchangeDate.contains(index) || i % paramScheduleSettingList.size() != 0) {

                        } else {
                            int a = i - paramScheduleSettingList.size() + 1;
                            for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                                DutyScheduleSet temp = getDayOfYBListForD(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                                DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                                dutyScheduleInfo.setSId(temp.getId());
                                dutyScheduleInfo.setSType("4");
                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                                dutyScheduleInfo.setDDept(temp.getDeptId());
                                BasePersonInfo basePersonInfo = getDailyPersonForD(a, dudyTemplates);
                                a++;
                                dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                                dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                                dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                                dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                                dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                                dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                                dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                                dutyScheduleInfo.setDDay(index);
                                dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                                dutyScheduleInfo.setDUserjob("处领导");
                                dutyScheduleInfo.setDutyType(DutyTypeEnum.DIRECTLY_DIVISION_LEADER.getValue());
                                dutyScheduleInfo.setDType("2");
                                ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                                DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                                dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                                } else {
                                    dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                                    dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                                }
                                dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                                result.add(dutyScheduleInfo);
                            }
                            return result;
                        }
                    default:
                        if (paramScheduleSettingList.size() ==1) {
                            flag--;
                            index = index.plusDays(1);
                        }
                        continue;
                }

            }
            DayOfWeek day = DayOfWeek.of(index.get(ChronoField.DAY_OF_WEEK));
            switch (day) {
                case SATURDAY:
                case SUNDAY:
                    //flag     1 2 3 4 5 6
                    //usedFlag 0 0 2 2 2 5
                    //         1 2 1 2 3 1
                    if (exchangeDate.contains(index)) {
                        flag--;
                        index = index.plusDays(1);
                    } else {
                        if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                            index = index.plusDays(1);
                            usedFlag += paramScheduleSettingList.size();
                        }
                    }
                    break;
                default:
                    flag--;
                    index = index.plusDays(1);
                    break;
            }
        }
        return result;
    }

    private List<DutyScheduleInfo> getHoilday(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                              List<ParamHolidays> importantDays,
                                              BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListVO.DudyTemplate> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZMB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (hoildayDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleSet temp = getDayOfYBList(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                        dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("2");
                        dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        dutyScheduleInfo.setDDept(temp.getDeptId());
                        BasePersonInfo basePersonInfo = getDailyPerson(a, dudyTemplates);
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("科员");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.DIRECTLY_SECTION_MEMBER.getValue());
                        dutyScheduleInfo.setDType("1");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                }
            }
            if (hoildayDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }


        return result;
    }


    private List<DutyScheduleInfo> getHoildayForZSS(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                    List<ParamHolidays> importantDays,
                                                    BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZMB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (hoildayDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleSet temp = getDayOfYBListForZSS(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                        dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("2");
                        dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        dutyScheduleInfo.setDDept(temp.getDeptId());
                        BasePersonInfo basePersonInfo = getDailyPersonForZSS(a, dudyTemplates);
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("署领导");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.GENERAL_ADMINISTRATION_LEADER.getValue());
                        ;
                        dutyScheduleInfo.setDType("2");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                }
            }
            if (hoildayDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }
        return result;
    }

    private List<DutyScheduleInfo> getHoildayForZST(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                    List<ParamHolidays> importantDays,
                                                    BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZMB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (hoildayDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleSet temp = getDayOfYBListForZST(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                        dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("2");
                        dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        dutyScheduleInfo.setDDept(temp.getDeptId());
                        BasePersonInfo basePersonInfo = getDailyPersonForZST(a, dudyTemplates);
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("司局领导");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.DEPARTMENT_EXCHANGE.getValue());
                        dutyScheduleInfo.setDType("2");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                }
            }
            if (hoildayDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }
        return result;
    }

    private List<DutyScheduleInfo> getHoildayForZSC(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                    List<ParamHolidays> importantDays,
                                                    BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZMB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (hoildayDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleSet temp = getDayOfYBListForZSC(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                        dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("2");
                        dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        dutyScheduleInfo.setDDept(temp.getDeptId());
                        BasePersonInfo basePersonInfo = getDailyPersonForZSC(a, dudyTemplates);
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("处领导");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.DIVISION_LEADER.getValue());
                        dutyScheduleInfo.setDType("2");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                }
            }
            if (hoildayDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }
        return result;
    }

    private List<DutyScheduleInfo> getHoildayForZSMain(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                       List<ParamHolidays> importantDays,
                                                       BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZMB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (hoildayDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleSet temp = getDayOfYBListForZSMain(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                        dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("2");
                        dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        dutyScheduleInfo.setDDept(temp.getDeptId());
                        BasePersonInfo basePersonInfo = getDailyPersonForZSMain(a, dudyTemplates);
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("主值班员");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.MASTER_DUTY.getValue());
                        dutyScheduleInfo.setDType("1");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                }
            }
            if (hoildayDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }
        return result;
    }

    private List<DutyScheduleInfo> getHoildayForZSSub(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                      List<ParamHolidays> importantDays,
                                                      BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZMB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (hoildayDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleSet temp = getDayOfYBListForZSSub(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                        dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("2");
                        dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        dutyScheduleInfo.setDDept(temp.getDeptId());
                        BasePersonInfo basePersonInfo = getDailyPersonForZSSub(a, dudyTemplates);
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("副值班员");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.DEPUTY_DUTY.getValue());
                        dutyScheduleInfo.setDType("1");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                }
            }
            if (hoildayDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }
        return result;
    }

    private List<DutyScheduleInfo> getHoildayForG(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                  List<ParamHolidays> importantDays,
                                                  BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListVO.DudyTemplate> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZMB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (hoildayDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
//                                dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("2");
//                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        BasePersonInfo basePersonInfo = getDailyPersonForG(a, persons, dutyPersonInitVO);
                        dutyScheduleInfo.setDDept(basePersonInfo.getDeptId());
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("关领导");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.DIRECTLY_CUSTOMS_LEADER.getValue());
                        dutyScheduleInfo.setDType("2");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                }
            }
            if (hoildayDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }


        return result;
    }

    private List<DutyScheduleInfo> getHoildayForD(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                  List<ParamHolidays> importantDays,
                                                  BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListVO.DudyTemplate> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZMB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (importantDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (hoildayDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleSet temp = getDayOfYBListForD(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                        dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("2");
                        dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        dutyScheduleInfo.setDDept(temp.getDeptId());
                        BasePersonInfo basePersonInfo = getDailyPersonForD(a, dudyTemplates);
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("处领导");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.DIVISION_LEADER.getValue());
                        dutyScheduleInfo.setDType("2");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                }
            }
            if (hoildayDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }


        return result;
    }

    private List<DutyScheduleInfo> getImportDayForG(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                    List<ParamHolidays> importantDays,
                                                    BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListVO.DudyTemplate> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZYB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (importantDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
//                                dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("3");
//                                dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        BasePersonInfo basePersonInfo = getDailyPersonForG(a, persons, dutyPersonInitVO);
                        dutyScheduleInfo.setDDept(basePersonInfo.getDeptId());
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("关领导");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.DIRECTLY_CUSTOMS_LEADER.getValue());
                        dutyScheduleInfo.setDType("2");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                } else {
                    if (paramScheduleSettingList.size() == 1) {
                        index = index.plusDays(1);
                        flag--;
                        continue;
                    }
                }
            }

            if (importantDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }


        return result;
    }

    private List<DutyScheduleInfo> getImportDay(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                List<ParamHolidays> importantDays,
                                                BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListVO.DudyTemplate> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZYB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (importantDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleSet temp = getDayOfYBList(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                        dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("3");
                        dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        dutyScheduleInfo.setDDept(temp.getDeptId());
                        BasePersonInfo basePersonInfo = getDailyPerson(a, dudyTemplates);
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("科员");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.DIRECTLY_SECTION_MEMBER.getValue());
                        dutyScheduleInfo.setDType("1");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                } else {
                    if (paramScheduleSettingList.size() == 1) {
                        index = index.plusDays(1);
                        flag--;
                        continue;
                    }
                }
            }

            if (importantDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }


        return result;
    }

    private List<DutyScheduleInfo> getImportDayForZSS(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                      List<ParamHolidays> importantDays,
                                                      BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZYB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (importantDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleSet temp = getDayOfYBListForZSS(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                        dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("3");
                        dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        dutyScheduleInfo.setDDept(temp.getDeptId());
                        BasePersonInfo basePersonInfo = getDailyPersonForZSS(a, dudyTemplates);
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("署领导");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.GENERAL_ADMINISTRATION_LEADER.getValue());
                        ;
                        dutyScheduleInfo.setDType("2");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                } else {
                    if (paramScheduleSettingList.size() == 1) {
                        index = index.plusDays(1);
                        flag--;
                        continue;
                    }
                }
            }

            if (importantDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }


        return result;
    }

    private List<DutyScheduleInfo> getImportDayForZST(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                      List<ParamHolidays> importantDays,
                                                      BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZYB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (importantDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleSet temp = getDayOfYBListForZST(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                        dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("3");
                        dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        dutyScheduleInfo.setDDept(temp.getDeptId());
                        BasePersonInfo basePersonInfo = getDailyPersonForZST(a, dudyTemplates);
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("司局领导");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.DEPARTMENT_EXCHANGE.getValue());
                        dutyScheduleInfo.setDType("2");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                } else {
                    if (paramScheduleSettingList.size() == 1) {
                        index = index.plusDays(1);
                        flag--;
                        continue;
                    }
                }
            }

            if (importantDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }


        return result;
    }

    private List<DutyScheduleInfo> getImportDayForZSC(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                      List<ParamHolidays> importantDays,
                                                      BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZYB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (importantDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleSet temp = getDayOfYBListForZSC(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                        dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("3");
                        dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        dutyScheduleInfo.setDDept(temp.getDeptId());
                        BasePersonInfo basePersonInfo = getDailyPersonForZSC(a, dudyTemplates);
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("处领导");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.DIVISION_LEADER.getValue());
                        dutyScheduleInfo.setDType("2");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                } else {
                    if (paramScheduleSettingList.size() == 1) {
                        index = index.plusDays(1);
                        flag--;
                        continue;
                    }
                }
            }

            if (importantDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }


        return result;
    }

    private List<DutyScheduleInfo> getImportDayForZSSub(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                        List<ParamHolidays> importantDays,
                                                        BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZYB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (importantDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleSet temp = getDayOfYBListForZSSub(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                        dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("3");
                        dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        dutyScheduleInfo.setDDept(temp.getDeptId());
                        BasePersonInfo basePersonInfo = getDailyPersonForZSSub(a, dudyTemplates);
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("副值班员");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.DEPARTMENT_EXCHANGE.getValue());
                        dutyScheduleInfo.setDType("1");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                } else {
                    if (paramScheduleSettingList.size() == 1) {
                        index = index.plusDays(1);
                        flag--;
                        continue;
                    }
                }
            }

            if (importantDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }


        return result;
    }

    private List<DutyScheduleInfo> getImportDayForZSMain(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                         List<ParamHolidays> importantDays,
                                                         BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZYB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (importantDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleSet temp = getDayOfYBListForZSMain(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                        dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("3");
                        dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        dutyScheduleInfo.setDDept(temp.getDeptId());
                        BasePersonInfo basePersonInfo = getDailyPersonForZSMain(a, dudyTemplates);
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("主值班员");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.MASTER_DUTY.getValue());
                        dutyScheduleInfo.setDType("1");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                } else {
                    if (paramScheduleSettingList.size() == 1) {
                        index = index.plusDays(1);
                        flag--;
                        continue;
                    }
                }
            }

            if (importantDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {
                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }


        return result;
    }

    private List<DutyScheduleInfo> getImportDayForD(Long sYear, Long sMonth, int i, List<ParamHolidays> holidays,
                                                    List<ParamHolidays> importantDays,
                                                    BaseDeptInfo custom, List<ParamHolidays> exhangeDays, List<DudyScheduleListVO.DudyTemplate> dudyTemplates, List<DutyScheduleSet> YBList, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates, List<BasePersonInfo> persons, DutyPersonInitVO dutyPersonInitVO) {
        LocalDate start = LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1);
        LocalDate index = start;
        List<LocalDate> hoildayDate = holidays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> importantDate = importantDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        List<LocalDate> exchangeDate = exhangeDays.stream().map(ParamHolidays::getHolidayDate).collect(Collectors.toList());
        Integer flag = 0;
        List<DutyScheduleInfo> result = new ArrayList<>();
        List<ParamScheduleSetting> paramScheduleSettingList = paramScheduleSettingRepository.getList(custom.getId(), SetDutyTypeEnum.TYPE_ZYB.getValue());
        int usedFlag = 0;
        while (flag < i) {
            if (hoildayDate.contains(index)) {
                index = index.plusDays(1);
                continue;
            }
            flag++;
            if (flag == i) {
                String dayOfWeek = DateUtil.getDaysOfWeek((long) index.getYear(), (long) index.getMonth().getValue(), index.getDayOfMonth());
                if (importantDate.contains(index) && i % paramScheduleSettingList.size() == 0) {
                    int a = i - paramScheduleSettingList.size() + 1;
                    for (ParamScheduleSetting paramScheduleSetting : paramScheduleSettingList) {
                        DutyScheduleSet temp = getDayOfYBListForD(a, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                        DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                        dutyScheduleInfo.setSId(temp.getId());
                        dutyScheduleInfo.setSType("3");
                        dutyScheduleInfo.setDDeptname(temp.getDeptName());
                        dutyScheduleInfo.setDDept(temp.getDeptId());
                        BasePersonInfo basePersonInfo = getDailyPersonForD(a, dudyTemplates);
                        a++;
                        dutyScheduleInfo.setDUserno(basePersonInfo.getUserno());
                        dutyScheduleInfo.setGlobalSort(basePersonInfo.getGlobalSort());
                        dutyScheduleInfo.setDUsername(basePersonInfo.getUsername());
                        dutyScheduleInfo.setPhoneShort(basePersonInfo.getPhoneShort());
                        dutyScheduleInfo.setDPhone(basePersonInfo.getPhone());
                        dutyScheduleInfo.setDPhoneLand(basePersonInfo.getPhoneLand());
                        dutyScheduleInfo.setDDayString(index.getMonth().getValue() + "月" + index.getDayOfMonth() + "日" + dayOfWeek);
                        dutyScheduleInfo.setDDay(index);
                        dutyScheduleInfo.setDutyTimesId(paramScheduleSetting.getParamDutyId());
                        dutyScheduleInfo.setDUserjob("处领导");
                        dutyScheduleInfo.setDutyType(DutyTypeEnum.DIRECTLY_DIVISION_LEADER.getValue());
                        dutyScheduleInfo.setDType("2");
                        ParamDuty paramDuty = guavacacheUtils.getParamDuty(paramScheduleSetting.getParamDutyId());
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm:ss");
                        dutyScheduleInfo.setDutyTimesString(DTypeEnum.getDescByCode(paramDuty.getDType()) + "(" + paramDuty.getDStartTime().format(format) + "~" + paramDuty.getDEndTime().format(format) + ")");
                        if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDEndTime()));
                        } else {
                            dutyScheduleInfo.setDStartDateTime(dutyScheduleInfo.getDDay().atTime(paramDuty.getDStartTime()));
                            dutyScheduleInfo.setDEndDateTime(dutyScheduleInfo.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                        }
                        dutyScheduleInfo.setDutyParamType(paramDuty.getDType());
                        result.add(dutyScheduleInfo);
                    }
                    return result;
                } else {
                    if (paramScheduleSettingList.size() == 1) {
                        index = index.plusDays(1);
                        flag--;
                        continue;
                    }
                }
            }

            if (importantDate.contains(index)) {
                if ((flag - usedFlag) % paramScheduleSettingList.size() == 0) {

                    index = index.plusDays(1);
                    usedFlag += paramScheduleSettingList.size();
                }
            } else {
                index = index.plusDays(1);
                flag--;
            }
        }


        return result;
    }


    private BasePersonInfo getDailyPerson(int i, List<DudyScheduleListVO.DudyTemplate> dudyTemplates) {
        int flag = 0;
        for (DudyScheduleListVO.DudyTemplate dudyTemplate : dudyTemplates) {
            flag += dudyTemplate.getSectionLevelDudyNumber();
            if (i <= flag) {
                BasePersonInfo basePersonInfo = dudyTemplate.getThisDeptPerson().get(dudyTemplate.getThisDeptPerson().size() - flag + i - 1);
                return basePersonInfo;
            }
        }
        return new BasePersonInfo();
    }


    private BasePersonInfo getDailyPersonForD(int i, List<DudyScheduleListVO.DudyTemplate> dudyTemplates) {
        int flag = 0;
        for (DudyScheduleListVO.DudyTemplate dudyTemplate : dudyTemplates) {
            flag += dudyTemplate.getDivisionLevelDudyNumber();
            if (i <= flag) {
                BasePersonInfo basePersonInfo = dudyTemplate.getThisDeptPerson().get(dudyTemplate.getThisDeptPerson().size() - flag + i - 1);
                return basePersonInfo;
            }
        }
        return new BasePersonInfo();
    }

    private BasePersonInfo getDailyPersonForZSS(int i, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates) {
        int flag = 0;
        for (DudyScheduleListZGVO.DudyTemplateZG dudyTemplate : dudyTemplates) {
            flag += dudyTemplate.getSLeaderCount();
            if (i <= flag) {
                BasePersonInfo basePersonInfo = dudyTemplate.getThisDeptPerson().get(dudyTemplate.getThisDeptPerson().size() - flag + i - 1);
                return basePersonInfo;
            }
        }
        return new BasePersonInfo();
    }

    private BasePersonInfo getDailyPersonForZST(int i, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates) {
        int flag = 0;
        for (DudyScheduleListZGVO.DudyTemplateZG dudyTemplate : dudyTemplates) {
            flag += dudyTemplate.getGLeaderCount();
            if (i <= flag) {
                BasePersonInfo basePersonInfo = dudyTemplate.getThisDeptPerson().get(dudyTemplate.getThisDeptPerson().size() - flag + i - 1);
                return basePersonInfo;
            }
        }
        return new BasePersonInfo();
    }

    private BasePersonInfo getDailyPersonForZSC(int i, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates) {
        int flag = 0;
        for (DudyScheduleListZGVO.DudyTemplateZG dudyTemplate : dudyTemplates) {
            flag += dudyTemplate.getCLeaderCount();
            if (i <= flag) {
                BasePersonInfo basePersonInfo = dudyTemplate.getThisDeptPerson().get(dudyTemplate.getThisDeptPerson().size() - flag + i - 1);
                return basePersonInfo;
            }
        }
        return new BasePersonInfo();
    }

    private BasePersonInfo getDailyPersonForZSMain(int i, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates) {
        int flag = 0;
        for (DudyScheduleListZGVO.DudyTemplateZG dudyTemplate : dudyTemplates) {
            flag += dudyTemplate.getMainDutyCount();
            if (i <= flag) {
                BasePersonInfo basePersonInfo = dudyTemplate.getThisDeptPerson().get(dudyTemplate.getThisDeptPerson().size() - flag + i - 1);
                return basePersonInfo;
            }
        }
        return new BasePersonInfo();
    }

    private BasePersonInfo getDailyPersonForZSSub(int i, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates) {
        int flag = 0;
        for (DudyScheduleListZGVO.DudyTemplateZG dudyTemplate : dudyTemplates) {
            flag += dudyTemplate.getSubDutyCount();
            if (i <= flag) {
                BasePersonInfo basePersonInfo = dudyTemplate.getThisDeptPerson().get(dudyTemplate.getThisDeptPerson().size() - flag + i - 1);
                return basePersonInfo;
            }
        }
        return new BasePersonInfo();
    }

    private DutyScheduleSet getDayOfYBList(int commonCount, List<DutyScheduleSet> ybList, List<DudyScheduleListVO.DudyTemplate> dailyDudyTemplates, List<DudyScheduleListVO.DudyTemplate> dudyTemplates, DutyPersonInitVO dutyPersonInitVO, List<BasePersonInfo> persons, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates) {
        long flag = 0;
        for (DudyScheduleListVO.DudyTemplate dudyTemplate : dailyDudyTemplates) {
            flag += dudyTemplate.getSectionLevelDudyNumber();
            if (commonCount <= flag) {
                DutyScheduleSet dutyScheduleSet = ybList.stream().filter(i -> i.getDeptId().equals(dudyTemplate.getDudyDeptId()))
                        .max(Comparator.comparing(i -> i.getId())).orElse(null);
                return dutyScheduleSet;
            }
        }
        return null;
    }

    private DutyScheduleSet getDayOfYBListForD(int commonCount, List<DutyScheduleSet> ybList, List<DudyScheduleListVO.DudyTemplate> dailyDudyTemplates, List<DudyScheduleListVO.DudyTemplate> dudyTemplates, DutyPersonInitVO dutyPersonInitVO, List<BasePersonInfo> persons, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates) {
        long flag = 0;
        for (DudyScheduleListVO.DudyTemplate dudyTemplate : dailyDudyTemplates) {
            flag += dudyTemplate.getDivisionLevelDudyNumber();
            if (commonCount <= flag) {
                DutyScheduleSet dutyScheduleSet = ybList.stream().filter(i -> i.getDeptId().equals(dudyTemplate.getDudyDeptId()))
                        .max(Comparator.comparing(i -> i.getId())).orElse(null);
                return dutyScheduleSet;
            }
        }
        return null;
    }

    private DutyScheduleSet getDayOfYBListForZSS(int commonCount, List<DutyScheduleSet> ybList, List<DudyScheduleListZGVO.DudyTemplateZG> dailyDudyTemplates, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, DutyPersonInitVO dutyPersonInitVO, List<BasePersonInfo> persons, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates) {
        long flag = 0;
        for (DudyScheduleListZGVO.DudyTemplateZG dudyTemplate : dailyDudyTemplates) {
            flag += dudyTemplate.getSLeaderCount();
            if (commonCount <= flag) {
                DutyScheduleSet dutyScheduleSet = ybList.stream().filter(i -> i.getDeptId().equals(dudyTemplate.getDudyDeptId()))
                        .max(Comparator.comparing(i -> i.getId())).orElse(null);
                return dutyScheduleSet;
            }
        }
        return null;
    }

    private DutyScheduleSet getDayOfYBListForZST(int commonCount, List<DutyScheduleSet> ybList, List<DudyScheduleListZGVO.DudyTemplateZG> dailyDudyTemplates, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, DutyPersonInitVO dutyPersonInitVO, List<BasePersonInfo> persons, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates) {
        long flag = 0;
        for (DudyScheduleListZGVO.DudyTemplateZG dudyTemplate : dailyDudyTemplates) {
            flag += dudyTemplate.getGLeaderCount();
            if (commonCount <= flag) {
                DutyScheduleSet dutyScheduleSet = ybList.stream().filter(i -> i.getDeptId().equals(dudyTemplate.getDudyDeptId()))
                        .max(Comparator.comparing(i -> i.getId())).orElse(null);
                return dutyScheduleSet;
            }
        }
        return null;
    }

    private DutyScheduleSet getDayOfYBListForZSC(int commonCount, List<DutyScheduleSet> ybList, List<DudyScheduleListZGVO.DudyTemplateZG> dailyDudyTemplates, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, DutyPersonInitVO dutyPersonInitVO, List<BasePersonInfo> persons, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates) {
        long flag = 0;
        for (DudyScheduleListZGVO.DudyTemplateZG dudyTemplate : dailyDudyTemplates) {
            flag += dudyTemplate.getCLeaderCount();
            if (commonCount <= flag) {
                DutyScheduleSet dutyScheduleSet = ybList.stream().filter(i -> i.getDeptId().equals(dudyTemplate.getDudyDeptId()))
                        .max(Comparator.comparing(i -> i.getId())).orElse(null);
                return dutyScheduleSet;
            }
        }
        return null;
    }

    private DutyScheduleSet getDayOfYBListForZSMain(int commonCount, List<DutyScheduleSet> ybList, List<DudyScheduleListZGVO.DudyTemplateZG> dailyDudyTemplates, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, DutyPersonInitVO dutyPersonInitVO, List<BasePersonInfo> persons, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates) {
        long flag = 0;
        for (DudyScheduleListZGVO.DudyTemplateZG dudyTemplate : dailyDudyTemplates) {
            flag += dudyTemplate.getMainDutyCount();
            if (commonCount <= flag) {
                DutyScheduleSet dutyScheduleSet = ybList.stream().filter(i -> i.getDeptId().equals(dudyTemplate.getDudyDeptId()))
                        .max(Comparator.comparing(i -> i.getId())).orElse(null);
                return dutyScheduleSet;
            }
        }
        return null;
    }

    private DutyScheduleSet getDayOfYBListForZSSub(int commonCount, List<DutyScheduleSet> ybList, List<DudyScheduleListZGVO.DudyTemplateZG> dailyDudyTemplates, List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates, DutyPersonInitVO dutyPersonInitVO, List<BasePersonInfo> persons, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates) {
        long flag = 0;
        for (DudyScheduleListZGVO.DudyTemplateZG dudyTemplate : dailyDudyTemplates) {
            flag += dudyTemplate.getSubDutyCount();
            if (commonCount <= flag) {
                DutyScheduleSet dutyScheduleSet = ybList.stream().filter(i -> i.getDeptId().equals(dudyTemplate.getDudyDeptId()))
                        .max(Comparator.comparing(i -> i.getId())).orElse(null);
                return dutyScheduleSet;
            }
        }
        return null;
    }


    private List<DudyScheduleListVO.DudyTemplate> createLineTemplates(List<DutyScheduleSet> yList, List<DudyScheduleListVO.DudyTemplate> dailyDudyTemplates, DutyPersonInitVO dutyPersonInitVO, List<BasePersonInfo> persons, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates) {
        List<DutyScheduleSet> ybList = yList.stream().map(i -> {
            DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
            BeanUtils.copyProperties(i, dutyScheduleSet);
            return dutyScheduleSet;
        }).collect(Collectors.toList());
        DudyScheduleListVO.DudyTemplate startTemplate = null;
        Map<String, DudyScheduleListVO.DudyTemplate> dudyTemplateMap = deptTemplates.stream().filter(j -> ybList.stream().map(i -> i.getDeptId()).collect(Collectors.toList())
                .contains(j.getDudyDeptId())).collect(Collectors.toMap(i -> i.getDudyDeptId(), i -> i));
        List<DudyScheduleListVO.DudyTemplate> resultTemplates = new ArrayList<>();
        Integer deptIndex = 0;
        boolean flag = true;
        for (int i = 0; i < ybList.size(); i++) {
            DutyScheduleSet dutyScheduleSet = ybList.get(i);
            DudyScheduleListVO.DudyTemplate dudyTemplate = new DudyScheduleListVO.DudyTemplate();
            BaseDeptInfo baseDeptInfo = baseDeptInfos.stream().filter(j -> j.getId().equals(dutyScheduleSet.getDeptId()))
                    .findFirst().orElse(null);
            if (baseDeptInfo == null) {
                continue;
            }
            List<BasePersonInfo> thisDept = dudyTemplateMap.get(dutyScheduleSet.getDeptId()).getThisDeptPerson();
            dudyTemplate.setSectionLevelDudyNumber(thisDept.size());
            dudyTemplate.setDudyDeptId(baseDeptInfo.getId());
            dudyTemplate.setDudyDept(baseDeptInfo.getDeptName());
            dudyTemplate.setSort(baseDeptInfo.getGlobalSort());
            if (thisDept.stream().map(BasePersonInfo::getUserno).collect(Collectors.toList()).contains(dutyPersonInitVO.getPersonNo())) {
                startTemplate = dudyTemplate;
                deptIndex = i;
                int personIndex = 0;
                for (int j = 0; j < thisDept.size(); j++) {
                    BasePersonInfo basePersonInfo = thisDept.get(j);
                    if (basePersonInfo.getUserno().equals(dutyPersonInitVO.getPersonNo())) {
                        personIndex = j;
                    }
                }
                List<BasePersonInfo> sortedPersonList = JSONArray.parseArray(JSONArray.toJSONString(thisDept.subList(personIndex, thisDept.size())), BasePersonInfo.class);
                sortedPersonList.addAll(thisDept.subList(0, personIndex));
                dudyTemplateMap.get(startTemplate.getDudyDeptId()).setThisDeptPerson(sortedPersonList);
}
        }
        if (startTemplate == null) {
            startTemplate = deptTemplates.get(0);
        }
        List<DutyScheduleSet> sortedYBList = JSONArray.parseArray(JSONArray.toJSONString(ybList.subList(deptIndex, ybList.size())), DutyScheduleSet.class);
        sortedYBList.addAll(ybList.subList(0, deptIndex));
        while (flag) {
            boolean tempFlag = false;
            for (DutyScheduleSet temp : sortedYBList) {
                if (temp.getSCount() == 0) {
                    tempFlag = true;
                } else {
                    tempFlag = false;
                    DudyScheduleListVO.DudyTemplate thisDept = dudyTemplateMap.get(temp.getDeptId());
                    if (temp.getSCount() >= thisDept.getSectionLevelDudyNumber()) {
                        DudyScheduleListVO.DudyTemplate dudyTemplate = new DudyScheduleListVO.DudyTemplate();
                        dudyTemplate.setSectionLevelDudyNumber(thisDept.getSectionLevelDudyNumber());
                        dudyTemplate.setDudyDeptId(temp.getDeptId());
                        dudyTemplate.setDudyDept(temp.getDeptName());
                        dudyTemplate.setSort(thisDept.getSort());
                        dudyTemplate.setThisDeptPerson(thisDept.getThisDeptPerson());
                        resultTemplates.add(dudyTemplate);
                        temp.setSCount(temp.getSCount() - thisDept.getSectionLevelDudyNumber());
                    } else {
                        DudyScheduleListVO.DudyTemplate dudyTemplate = new DudyScheduleListVO.DudyTemplate();
                        dudyTemplate.setSectionLevelDudyNumber((int) (long) temp.getSCount());
                        dudyTemplate.setDudyDeptId(temp.getDeptId());
                        dudyTemplate.setDudyDept(temp.getDeptName());
                        dudyTemplate.setSort(thisDept.getSort());
                        dudyTemplate.setThisDeptPerson(thisDept.getThisDeptPerson().subList(0, dudyTemplate.getSectionLevelDudyNumber()));
                        resultTemplates.add(dudyTemplate);
                        temp.setSCount(0l);
                    }
                }
            }
            if (sortedYBList.stream().filter(i -> i.getSCount() != 0).count() == 0) {
                break;
            }
        }
        return resultTemplates;
    }


    private List<DudyScheduleListZGVO.DudyTemplateZG> createLineTemplatesFosSLeader(List<DutyScheduleSet> yList, List<DudyScheduleListVO.DudyTemplate> dailyDudyTemplates, DutyPersonInitVO dutyPersonInitVO, List<BasePersonInfo> persons, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates) {
        List<DutyScheduleSet> ybList = yList.stream().map(i -> {
            DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
            BeanUtils.copyProperties(i, dutyScheduleSet);
            return dutyScheduleSet;
        }).collect(Collectors.toList());
        DudyScheduleListZGVO.DudyTemplateZG startTemplate = null;
        Map<String, DudyScheduleListZGVO.DudyTemplateZG> dudyTemplateMap = deptTemplates.stream().filter(j -> ybList.stream().map(i -> i.getDeptId()).collect(Collectors.toList())
                .contains(j.getDudyDeptId())).collect(Collectors.toMap(i -> i.getDudyDeptId(), i -> i));
        List<DudyScheduleListZGVO.DudyTemplateZG> resultTemplates = new ArrayList<>();
        Integer deptIndex = 0;
        boolean flag = true;
        for (int i = 0; i < ybList.size(); i++) {
            DutyScheduleSet dutyScheduleSet = ybList.get(i);
            DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
            BaseDeptInfo baseDeptInfo = baseDeptInfos.stream().filter(j -> j.getId().equals(dutyScheduleSet.getDeptId()))
                    .findFirst().orElse(null);
            if (baseDeptInfo == null) {
                continue;
            }
            List<BasePersonInfo> thisDept = dudyTemplateMap.get(dutyScheduleSet.getDeptId()).getThisDeptPerson();
            dudyTemplate.setSLeaderCount(thisDept.size());
            dudyTemplate.setDudyDeptId(baseDeptInfo.getId());
            dudyTemplate.setDudyDept(baseDeptInfo.getDeptName());
            dudyTemplate.setSort(baseDeptInfo.getGlobalSort());
            if (thisDept.stream().map(BasePersonInfo::getUserno).collect(Collectors.toList()).contains(dutyPersonInitVO.getPersonNo())) {
                startTemplate = dudyTemplate;
                deptIndex = i;
                int personIndex = 0;
                for (int j = 0; j < thisDept.size(); j++) {
                    BasePersonInfo basePersonInfo = thisDept.get(j);
                    if (basePersonInfo.getUserno().equals(dutyPersonInitVO.getPersonNo())) {
                        personIndex = j;
                    }
                }
                List<BasePersonInfo> sortedPersonList = JSONArray.parseArray(JSONArray.toJSONString(thisDept.subList(personIndex, thisDept.size())), BasePersonInfo.class);
                sortedPersonList.addAll(thisDept.subList(0, personIndex));
                dudyTemplateMap.get(startTemplate.getDudyDeptId()).setThisDeptPerson(sortedPersonList);
}
        }
        if (startTemplate == null) {
            startTemplate = deptTemplates.get(0);
        }
        List<DutyScheduleSet> sortedYBList = JSONArray.parseArray(JSONArray.toJSONString(ybList.subList(deptIndex, ybList.size())), DutyScheduleSet.class);
        sortedYBList.addAll(ybList.subList(0, deptIndex));
        while (flag) {
            boolean tempFlag = false;
            for (DutyScheduleSet temp : sortedYBList) {
                if (temp.getZsSCount() == 0) {
                    tempFlag = true;
                } else {
                    tempFlag = false;
                    DudyScheduleListZGVO.DudyTemplateZG thisDept = dudyTemplateMap.get(temp.getDeptId());
                    if (temp.getZsSCount() >= thisDept.getSLeaderCount()) {
                        DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                        dudyTemplate.setSLeaderCount(thisDept.getSLeaderCount());
                        dudyTemplate.setDudyDeptId(temp.getDeptId());
                        dudyTemplate.setDudyDept(temp.getDeptName());
                        dudyTemplate.setSort(thisDept.getSort());
                        dudyTemplate.setThisDeptPerson(thisDept.getThisDeptPerson());
                        resultTemplates.add(dudyTemplate);
                        temp.setZsSCount(temp.getZsSCount() - thisDept.getSLeaderCount());
                    } else {
                        DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                        dudyTemplate.setSLeaderCount((int) (long) temp.getZsSCount());
                        dudyTemplate.setDudyDeptId(temp.getDeptId());
                        dudyTemplate.setDudyDept(temp.getDeptName());
                        dudyTemplate.setSort(thisDept.getSort());
                        dudyTemplate.setThisDeptPerson(thisDept.getThisDeptPerson().subList(0, dudyTemplate.getSLeaderCount()));
                        resultTemplates.add(dudyTemplate);
                        temp.setZsSCount(0l);
                    }
                }
            }
            if (sortedYBList.stream().filter(i -> i.getZsSCount() != 0).count() == 0) {
                break;
            }
        }
        return resultTemplates;
    }

    private List<DudyScheduleListZGVO.DudyTemplateZG> createLineTemplatesForTLeader(List<DutyScheduleSet> yList, List<DudyScheduleListVO.DudyTemplate> dailyDudyTemplates, DutyPersonInitVO dutyPersonInitVO, List<BasePersonInfo> persons, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates) {
        List<DutyScheduleSet> ybList = yList.stream().map(i -> {
            DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
            BeanUtils.copyProperties(i, dutyScheduleSet);
            return dutyScheduleSet;
        }).collect(Collectors.toList());
        DudyScheduleListZGVO.DudyTemplateZG startTemplate = null;
        Map<String, DudyScheduleListZGVO.DudyTemplateZG> dudyTemplateMap = deptTemplates.stream().filter(j -> ybList.stream().map(i -> i.getDeptId()).collect(Collectors.toList())
                .contains(j.getDudyDeptId())).collect(Collectors.toMap(i -> i.getDudyDeptId(), i -> i));
        List<DudyScheduleListZGVO.DudyTemplateZG> resultTemplates = new ArrayList<>();
        Integer deptIndex = 0;
        boolean flag = true;
        for (int i = 0; i < ybList.size(); i++) {
            DutyScheduleSet dutyScheduleSet = ybList.get(i);
            DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
            BaseDeptInfo baseDeptInfo = baseDeptInfos.stream().filter(j -> j.getId().equals(dutyScheduleSet.getDeptId()))
                    .findFirst().orElse(null);
            if (baseDeptInfo == null) {
                continue;
            }
            List<BasePersonInfo> thisDept = dudyTemplateMap.get(dutyScheduleSet.getDeptId()).getThisDeptPerson();
            dudyTemplate.setGLeaderCount(thisDept.size());
            dudyTemplate.setDudyDeptId(baseDeptInfo.getId());
            dudyTemplate.setDudyDept(baseDeptInfo.getDeptName());
            dudyTemplate.setSort(baseDeptInfo.getGlobalSort());
            if (thisDept.stream().map(BasePersonInfo::getUserno).collect(Collectors.toList()).contains(dutyPersonInitVO.getPersonNo())) {
                startTemplate = dudyTemplate;
                deptIndex = i;
                int personIndex = 0;
                for (int j = 0; j < thisDept.size(); j++) {
                    BasePersonInfo basePersonInfo = thisDept.get(j);
                    if (basePersonInfo.getUserno().equals(dutyPersonInitVO.getPersonNo())) {
                        personIndex = j;
                    }
                }
                List<BasePersonInfo> sortedPersonList = JSONArray.parseArray(JSONArray.toJSONString(thisDept.subList(personIndex, thisDept.size())), BasePersonInfo.class);
                sortedPersonList.addAll(thisDept.subList(0, personIndex));
                dudyTemplateMap.get(startTemplate.getDudyDeptId()).setThisDeptPerson(sortedPersonList);
}
        }
        if (startTemplate == null) {
            startTemplate = deptTemplates.get(0);
        }
        List<DutyScheduleSet> sortedYBList = JSONArray.parseArray(JSONArray.toJSONString(ybList.subList(deptIndex, ybList.size())), DutyScheduleSet.class);
        sortedYBList.addAll(ybList.subList(0, deptIndex));
        while (flag) {
            boolean tempFlag = false;
            for (DutyScheduleSet temp : sortedYBList) {
                if (temp.getZsTCount() == 0) {
                    tempFlag = true;
                } else {
                    tempFlag = false;
                    DudyScheduleListZGVO.DudyTemplateZG thisDept = dudyTemplateMap.get(temp.getDeptId());
                    if (temp.getZsTCount() >= thisDept.getGLeaderCount()) {
                        DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                        dudyTemplate.setGLeaderCount(thisDept.getGLeaderCount());
                        dudyTemplate.setDudyDeptId(temp.getDeptId());
                        dudyTemplate.setDudyDept(temp.getDeptName());
                        dudyTemplate.setSort(thisDept.getSort());
                        dudyTemplate.setThisDeptPerson(thisDept.getThisDeptPerson());
                        resultTemplates.add(dudyTemplate);
                        temp.setZsTCount(temp.getZsTCount() - thisDept.getGLeaderCount());
                    } else {
                        DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                        dudyTemplate.setGLeaderCount((int) (long) temp.getZsTCount());
                        dudyTemplate.setDudyDeptId(temp.getDeptId());
                        dudyTemplate.setDudyDept(temp.getDeptName());
                        dudyTemplate.setSort(thisDept.getSort());
                        dudyTemplate.setThisDeptPerson(thisDept.getThisDeptPerson().subList(0, dudyTemplate.getGLeaderCount()));
                        resultTemplates.add(dudyTemplate);
                        temp.setZsTCount(0l);
                    }
                }
            }
            if (sortedYBList.stream().filter(i -> i.getZsTCount() != 0).count() == 0) {
                break;
            }
        }
        return resultTemplates;
    }

    private List<DudyScheduleListZGVO.DudyTemplateZG> createLineTemplatesForCLeader(List<DutyScheduleSet> yList, List<DudyScheduleListVO.DudyTemplate> dailyDudyTemplates, DutyPersonInitVO dutyPersonInitVO, List<BasePersonInfo> persons, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates) {
        List<DutyScheduleSet> ybList = yList.stream().map(i -> {
            DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
            BeanUtils.copyProperties(i, dutyScheduleSet);
            return dutyScheduleSet;
        }).collect(Collectors.toList());
        DudyScheduleListZGVO.DudyTemplateZG startTemplate = null;
        Map<String, DudyScheduleListZGVO.DudyTemplateZG> dudyTemplateMap = deptTemplates.stream().filter(j -> ybList.stream().map(i -> i.getDeptId()).collect(Collectors.toList())
                .contains(j.getDudyDeptId())).collect(Collectors.toMap(i -> i.getDudyDeptId(), i -> i));
        List<DudyScheduleListZGVO.DudyTemplateZG> resultTemplates = new ArrayList<>();
        Integer deptIndex = 0;
        boolean flag = true;
        for (int i = 0; i < ybList.size(); i++) {
            DutyScheduleSet dutyScheduleSet = ybList.get(i);
            DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
            BaseDeptInfo baseDeptInfo = baseDeptInfos.stream().filter(j -> j.getId().equals(dutyScheduleSet.getDeptId()))
                    .findFirst().orElse(null);
            if (baseDeptInfo == null) {
                continue;
            }
            List<BasePersonInfo> thisDept = dudyTemplateMap.get(dutyScheduleSet.getDeptId()).getThisDeptPerson();
            dudyTemplate.setCLeaderCount(thisDept.size());
            dudyTemplate.setDudyDeptId(baseDeptInfo.getId());
            dudyTemplate.setDudyDept(baseDeptInfo.getDeptName());
            dudyTemplate.setSort(baseDeptInfo.getGlobalSort());
            if (thisDept.stream().map(BasePersonInfo::getUserno).collect(Collectors.toList()).contains(dutyPersonInitVO.getPersonNo())) {
                startTemplate = dudyTemplate;
                deptIndex = i;
                int personIndex = 0;
                for (int j = 0; j < thisDept.size(); j++) {
                    BasePersonInfo basePersonInfo = thisDept.get(j);
                    if (basePersonInfo.getUserno().equals(dutyPersonInitVO.getPersonNo())) {
                        personIndex = j;
                    }
                }
                List<BasePersonInfo> sortedPersonList = JSONArray.parseArray(JSONArray.toJSONString(thisDept.subList(personIndex, thisDept.size())), BasePersonInfo.class);
                sortedPersonList.addAll(thisDept.subList(0, personIndex));
                dudyTemplateMap.get(startTemplate.getDudyDeptId()).setThisDeptPerson(sortedPersonList);
}
        }
        if (startTemplate == null) {
            startTemplate = deptTemplates.get(0);
        }
        List<DutyScheduleSet> sortedYBList = JSONArray.parseArray(JSONArray.toJSONString(ybList.subList(deptIndex, ybList.size())), DutyScheduleSet.class);
        sortedYBList.addAll(ybList.subList(0, deptIndex));
        while (flag) {
            boolean tempFlag = false;
            for (DutyScheduleSet temp : sortedYBList) {
                if (temp.getZsCCount() == 0) {
                    tempFlag = true;
                } else {
                    tempFlag = false;
                    DudyScheduleListZGVO.DudyTemplateZG thisDept = dudyTemplateMap.get(temp.getDeptId());
                    if (temp.getZsCCount() >= thisDept.getCLeaderCount()) {
                        DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                        dudyTemplate.setCLeaderCount(thisDept.getCLeaderCount());
                        dudyTemplate.setDudyDeptId(temp.getDeptId());
                        dudyTemplate.setDudyDept(temp.getDeptName());
                        dudyTemplate.setSort(thisDept.getSort());
                        dudyTemplate.setThisDeptPerson(thisDept.getThisDeptPerson());
                        resultTemplates.add(dudyTemplate);
                        temp.setZsCCount(temp.getZsCCount() - thisDept.getCLeaderCount());
                    } else {
                        DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                        dudyTemplate.setCLeaderCount((int) (long) temp.getZsCCount());
                        dudyTemplate.setDudyDeptId(temp.getDeptId());
                        dudyTemplate.setDudyDept(temp.getDeptName());
                        dudyTemplate.setSort(thisDept.getSort());
                        dudyTemplate.setThisDeptPerson(thisDept.getThisDeptPerson().subList(0, dudyTemplate.getCLeaderCount()));
                        resultTemplates.add(dudyTemplate);
                        temp.setZsCCount(0l);
                    }
                }
            }
            if (sortedYBList.stream().filter(i -> i.getZsCCount() != 0).count() == 0) {
                break;
            }
        }
        return resultTemplates;
    }

    private List<DudyScheduleListZGVO.DudyTemplateZG> createLineTemplatesForMainDuty(List<DutyScheduleSet> yList, List<DudyScheduleListVO.DudyTemplate> dailyDudyTemplates, DutyPersonInitVO dutyPersonInitVO, List<BasePersonInfo> persons, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates) {
        List<DutyScheduleSet> ybList = yList.stream().map(i -> {
            DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
            BeanUtils.copyProperties(i, dutyScheduleSet);
            return dutyScheduleSet;
        }).collect(Collectors.toList());
        DudyScheduleListZGVO.DudyTemplateZG startTemplate = null;
        Map<String, DudyScheduleListZGVO.DudyTemplateZG> dudyTemplateMap = deptTemplates.stream().filter(j -> ybList.stream().map(i -> i.getDeptId()).collect(Collectors.toList())
                .contains(j.getDudyDeptId())).collect(Collectors.toMap(i -> i.getDudyDeptId(), i -> i));
        List<DudyScheduleListZGVO.DudyTemplateZG> resultTemplates = new ArrayList<>();
        Integer deptIndex = 0;
        boolean flag = true;
        for (int i = 0; i < ybList.size(); i++) {
            DutyScheduleSet dutyScheduleSet = ybList.get(i);
            DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
            BaseDeptInfo baseDeptInfo = baseDeptInfos.stream().filter(j -> j.getId().equals(dutyScheduleSet.getDeptId()))
                    .findFirst().orElse(null);
            if (baseDeptInfo == null) {
                continue;
            }
            List<BasePersonInfo> thisDept = dudyTemplateMap.get(dutyScheduleSet.getDeptId()).getThisDeptPerson();
            dudyTemplate.setMainDutyCount(thisDept.size());
            dudyTemplate.setDudyDeptId(baseDeptInfo.getId());
            dudyTemplate.setDudyDept(baseDeptInfo.getDeptName());
            dudyTemplate.setSort(baseDeptInfo.getGlobalSort());
            if (thisDept.stream().map(BasePersonInfo::getUserno).collect(Collectors.toList()).contains(dutyPersonInitVO.getPersonNo())) {
                startTemplate = dudyTemplate;
                deptIndex = i;
                int personIndex = 0;
                for (int j = 0; j < thisDept.size(); j++) {
                    BasePersonInfo basePersonInfo = thisDept.get(j);
                    if (basePersonInfo.getUserno().equals(dutyPersonInitVO.getPersonNo())) {
                        personIndex = j;
                    }
                }
                List<BasePersonInfo> sortedPersonList = JSONArray.parseArray(JSONArray.toJSONString(thisDept.subList(personIndex, thisDept.size())), BasePersonInfo.class);
                sortedPersonList.addAll(thisDept.subList(0, personIndex));
                dudyTemplateMap.get(startTemplate.getDudyDeptId()).setThisDeptPerson(sortedPersonList);
}
        }
        if (startTemplate == null) {
            startTemplate = deptTemplates.get(0);
        }
        List<DutyScheduleSet> sortedYBList = JSONArray.parseArray(JSONArray.toJSONString(ybList.subList(deptIndex, ybList.size())), DutyScheduleSet.class);
        sortedYBList.addAll(ybList.subList(0, deptIndex));
        while (flag) {
            boolean tempFlag = false;
            for (DutyScheduleSet temp : sortedYBList) {
                if (temp.getZsMainCount() == 0) {
                    tempFlag = true;
                } else {
                    tempFlag = false;
                    DudyScheduleListZGVO.DudyTemplateZG thisDept = dudyTemplateMap.get(temp.getDeptId());
                    if (temp.getZsMainCount() >= thisDept.getMainDutyCount()) {
                        DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                        dudyTemplate.setMainDutyCount(thisDept.getMainDutyCount());
                        dudyTemplate.setDudyDeptId(temp.getDeptId());
                        dudyTemplate.setDudyDept(temp.getDeptName());
                        dudyTemplate.setSort(thisDept.getSort());
                        dudyTemplate.setThisDeptPerson(thisDept.getThisDeptPerson());
                        resultTemplates.add(dudyTemplate);
                        temp.setZsMainCount(temp.getZsMainCount() - thisDept.getMainDutyCount());
                    } else {
                        DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                        dudyTemplate.setMainDutyCount((int) (long) temp.getZsMainCount());
                        dudyTemplate.setDudyDeptId(temp.getDeptId());
                        dudyTemplate.setDudyDept(temp.getDeptName());
                        dudyTemplate.setSort(thisDept.getSort());
                        dudyTemplate.setThisDeptPerson(thisDept.getThisDeptPerson().subList(0, dudyTemplate.getMainDutyCount()));
                        resultTemplates.add(dudyTemplate);
                        temp.setZsMainCount(0l);
                    }
                }
            }
            if (sortedYBList.stream().filter(i -> i.getZsMainCount() != 0).count() == 0) {
                break;
            }
        }
        return resultTemplates;
    }

    private List<DudyScheduleListZGVO.DudyTemplateZG> createLineTemplatesForSubDuty(List<DutyScheduleSet> yList, List<DudyScheduleListVO.DudyTemplate> dailyDudyTemplates, DutyPersonInitVO dutyPersonInitVO, List<BasePersonInfo> persons, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates) {
        List<DutyScheduleSet> ybList = yList.stream().map(i -> {
            DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
            BeanUtils.copyProperties(i, dutyScheduleSet);
            return dutyScheduleSet;
        }).collect(Collectors.toList());
        DudyScheduleListZGVO.DudyTemplateZG startTemplate = null;
        Map<String, DudyScheduleListZGVO.DudyTemplateZG> dudyTemplateMap = deptTemplates.stream().filter(j -> ybList.stream().map(i -> i.getDeptId()).collect(Collectors.toList())
                .contains(j.getDudyDeptId())).collect(Collectors.toMap(i -> i.getDudyDeptId(), i -> i));
        List<DudyScheduleListZGVO.DudyTemplateZG> resultTemplates = new ArrayList<>();
        Integer deptIndex = 0;
        boolean flag = true;
        for (int i = 0; i < ybList.size(); i++) {
            DutyScheduleSet dutyScheduleSet = ybList.get(i);
            DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
            BaseDeptInfo baseDeptInfo = baseDeptInfos.stream().filter(j -> j.getId().equals(dutyScheduleSet.getDeptId()))
                    .findFirst().orElse(null);
            if (baseDeptInfo == null) {
                continue;
            }
            List<BasePersonInfo> thisDept = dudyTemplateMap.get(dutyScheduleSet.getDeptId()).getThisDeptPerson();
            dudyTemplate.setSubDutyCount(thisDept.size());
            dudyTemplate.setDudyDeptId(baseDeptInfo.getId());
            dudyTemplate.setDudyDept(baseDeptInfo.getDeptName());
            dudyTemplate.setSort(baseDeptInfo.getGlobalSort());
            if (thisDept.stream().map(BasePersonInfo::getUserno).collect(Collectors.toList()).contains(dutyPersonInitVO.getPersonNo())) {
                startTemplate = dudyTemplate;
                deptIndex = i;
                int personIndex = 0;
                for (int j = 0; j < thisDept.size(); j++) {
                    BasePersonInfo basePersonInfo = thisDept.get(j);
                    if (basePersonInfo.getUserno().equals(dutyPersonInitVO.getPersonNo())) {
                        personIndex = j;
                    }
                }
                List<BasePersonInfo> sortedPersonList = JSONArray.parseArray(JSONArray.toJSONString(thisDept.subList(personIndex, thisDept.size())), BasePersonInfo.class);
                sortedPersonList.addAll(thisDept.subList(0, personIndex));
                dudyTemplateMap.get(startTemplate.getDudyDeptId()).setThisDeptPerson(sortedPersonList);
}
        }
        if (startTemplate == null) {
            startTemplate = deptTemplates.get(0);
        }
        List<DutyScheduleSet> sortedYBList = JSONArray.parseArray(JSONArray.toJSONString(ybList.subList(deptIndex, ybList.size())), DutyScheduleSet.class);
        sortedYBList.addAll(ybList.subList(0, deptIndex));
        while (flag) {
            boolean tempFlag = false;
            for (DutyScheduleSet temp : sortedYBList) {
                if (temp.getZsSubCount() == 0) {
                    tempFlag = true;
                } else {
                    tempFlag = false;
                    DudyScheduleListZGVO.DudyTemplateZG thisDept = dudyTemplateMap.get(temp.getDeptId());
                    if (temp.getZsSubCount() >= thisDept.getSubDutyCount()) {
                        DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                        dudyTemplate.setSubDutyCount(thisDept.getSubDutyCount());
                        dudyTemplate.setDudyDeptId(temp.getDeptId());
                        dudyTemplate.setDudyDept(temp.getDeptName());
                        dudyTemplate.setSort(thisDept.getSort());
                        dudyTemplate.setThisDeptPerson(thisDept.getThisDeptPerson());
                        resultTemplates.add(dudyTemplate);
                        temp.setZsSubCount(temp.getZsSubCount() - thisDept.getSubDutyCount());
                    } else {
                        DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                        dudyTemplate.setSubDutyCount((int) (long) temp.getZsSubCount());
                        dudyTemplate.setDudyDeptId(temp.getDeptId());
                        dudyTemplate.setDudyDept(temp.getDeptName());
                        dudyTemplate.setSort(thisDept.getSort());
                        dudyTemplate.setThisDeptPerson(thisDept.getThisDeptPerson().subList(0, dudyTemplate.getSubDutyCount()));
                        resultTemplates.add(dudyTemplate);
                        temp.setZsSubCount(0l);
                    }
                }
            }
            if (sortedYBList.stream().filter(i -> i.getZsSubCount() != 0).count() == 0) {
                break;
            }
        }
        return resultTemplates;
    }

    private List<DudyScheduleListVO.DudyTemplate> createLineTemplatesForD(List<DutyScheduleSet> yList, List<DudyScheduleListVO.DudyTemplate> dailyDudyTemplates, DutyPersonInitVO dutyPersonInitVO, List<BasePersonInfo> persons, List<BaseDeptInfo> allDepts, List<BaseDeptInfo> baseDeptInfos, List<DudyScheduleListVO.DudyTemplate> deptTemplates) {
        List<DutyScheduleSet> ybList = yList.stream().map(i -> {
            DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
            BeanUtils.copyProperties(i, dutyScheduleSet);
            return dutyScheduleSet;
        }).collect(Collectors.toList());
        DudyScheduleListVO.DudyTemplate startTemplate = null;
        Map<String, BaseDeptInfo> baseDeptInfoMap = baseDeptInfos.stream().collect(Collectors.toMap(i -> i.getId(), i -> i));
        Map<String, DudyScheduleListVO.DudyTemplate> dudyTemplateMap = deptTemplates.stream().filter(j -> ybList.stream().map(i -> i.getDeptId()).collect(Collectors.toList())
                .contains(j.getDudyDeptId())).collect(Collectors.toMap(i -> i.getDudyDeptId(), i -> i));
        List<DudyScheduleListVO.DudyTemplate> resultTemplates = new ArrayList<>();
        Integer deptIndex = 0;
        boolean flag = true;
        for (int i = 0; i < ybList.size(); i++) {
            DutyScheduleSet dutyScheduleSet = ybList.get(i);
            DudyScheduleListVO.DudyTemplate dudyTemplate = new DudyScheduleListVO.DudyTemplate();
            BaseDeptInfo baseDeptInfo = baseDeptInfos.stream().filter(j -> j.getId().equals(dutyScheduleSet.getDeptId()))
                    .findFirst().orElse(null);
            if (baseDeptInfo == null) {
                continue;
            }
            List<BasePersonInfo> thisDept = dudyTemplateMap.get(dutyScheduleSet.getDeptId()).getThisDeptPerson();
            dudyTemplate.setDivisionLevelDudyNumber(thisDept.size());
            dudyTemplate.setDudyDeptId(baseDeptInfo.getId());
            dudyTemplate.setDudyDept(baseDeptInfo.getDeptName());
            dudyTemplate.setSort(baseDeptInfo.getGlobalSort());
            if (thisDept.stream().map(BasePersonInfo::getUserno).collect(Collectors.toList()).contains(dutyPersonInitVO.getPersonNo())) {
                startTemplate = dudyTemplate;
                deptIndex = i;
                int personIndex = 0;
                for (int j = 0; j < thisDept.size(); j++) {
                    BasePersonInfo basePersonInfo = thisDept.get(j);
                    if (basePersonInfo.getUserno().equals(dutyPersonInitVO.getPersonNo())) {
                        personIndex = j;
                    }
                }
                List<BasePersonInfo> sortedPersonList = JSONArray.parseArray(JSONArray.toJSONString(thisDept.subList(personIndex, thisDept.size())), BasePersonInfo.class);
                sortedPersonList.addAll(thisDept.subList(0, personIndex));
                dudyTemplateMap.get(startTemplate.getDudyDeptId()).setThisDeptPerson(sortedPersonList);
}
        }
        if (startTemplate == null) {
            startTemplate = deptTemplates.get(0);
        }
        List<DutyScheduleSet> sortedYBList = JSONArray.parseArray(JSONArray.toJSONString(ybList.subList(deptIndex, ybList.size())), DutyScheduleSet.class);
        sortedYBList.addAll(ybList.subList(0, deptIndex));
        while (flag) {
            int index = 0;
            for (DutyScheduleSet temp : sortedYBList) {
                DudyScheduleListVO.DudyTemplate thisDept = dudyTemplateMap.get(temp.getDeptId());
                if (temp.getDCount() >= thisDept.getDivisionLevelDudyNumber()) {
                    DudyScheduleListVO.DudyTemplate dudyTemplate = new DudyScheduleListVO.DudyTemplate();
                    dudyTemplate.setDivisionLevelDudyNumber(thisDept.getDivisionLevelDudyNumber());
                    dudyTemplate.setDudyDeptId(temp.getDeptId());
                    dudyTemplate.setDudyDept(temp.getDeptName());
                    dudyTemplate.setSort(thisDept.getSort());
                    dudyTemplate.setThisDeptPerson(thisDept.getThisDeptPerson());
                    resultTemplates.add(dudyTemplate);
                    temp.setDCount(temp.getDCount() - thisDept.getDivisionLevelDudyNumber());
                } else {
                    DudyScheduleListVO.DudyTemplate dudyTemplate = new DudyScheduleListVO.DudyTemplate();
                    dudyTemplate.setDivisionLevelDudyNumber((int) (long) temp.getDCount());
                    dudyTemplate.setDudyDeptId(temp.getDeptId());
                    dudyTemplate.setDudyDept(temp.getDeptName());
                    dudyTemplate.setSort(thisDept.getSort());
                    dudyTemplate.setThisDeptPerson(thisDept.getThisDeptPerson().subList(0, dudyTemplate.getDivisionLevelDudyNumber()));
                    resultTemplates.add(dudyTemplate);
                    temp.setDCount(0l);
                }
            }
            if (sortedYBList.stream().filter(i -> i.getDCount() != 0).count() == 0) {
                break;
            }
        }
        return resultTemplates;
    }


    private List<DudyScheduleListVO.DudyTemplate> createLineTemplatesCJ(List<DutyScheduleSet> yList, List<DudyScheduleListVO.DudyTemplate> dailyDudyTemplates) {
        List<DutyScheduleSet> ybList = yList.stream().map(i -> {
            DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
            BeanUtils.copyProperties(i, dutyScheduleSet);
            return dutyScheduleSet;
        }).collect(Collectors.toList());
        Integer maxRound = ybList.stream().map(DutyScheduleSet::getRound).max(Comparator.comparing(i -> i)).orElse(1);
        List<DudyScheduleListVO.DudyTemplate> result = new ArrayList<>();
        if (maxRound <= 1) {
            List<DudyScheduleListVO.DudyTemplate> temp = ybList.stream().map(a -> {
                DudyScheduleListVO.DudyTemplate dudyTemp = new DudyScheduleListVO.DudyTemplate();
                dudyTemp.setSectionLevelDudyNumber((int) (long) a.getSCount());
                dudyTemp.setDivisionLevelDudyNumber((int) (long) a.getDCount());
                dudyTemp.setDudyDept(a.getSDept());
                dudyTemp.setDudyDeptId(a.getDeptId());
                return dudyTemp;
            }).collect(Collectors.toList());
            return temp;
        } else {
            for (int i = 1; i <= maxRound; i++) {
                List<DutyScheduleSet> levelOneList = ybList.stream().filter(j -> j.getRound().equals(1)).collect(Collectors.toList());
                if (!CollectionUtils.isEmpty(levelOneList)) {
                    List<DudyScheduleListVO.DudyTemplate> temp = levelOneList.stream().map(a -> {
                        DudyScheduleListVO.DudyTemplate dudyTemp = new DudyScheduleListVO.DudyTemplate();
                        dudyTemp.setSectionLevelDudyNumber((int) (long) a.getSCount());
                        dudyTemp.setDivisionLevelDudyNumber((int) (long) a.getDCount());
                        dudyTemp.setDudyDept(a.getSDept());
                        dudyTemp.setDudyDeptId(a.getDeptId());
                        return dudyTemp;
                    }).collect(Collectors.toList());
                    result.addAll(temp);
//                    List<DutyScheduleSet> others = ybList.stream().filter(j -> !j.getRound().equals(1)).collect(Collectors.toList());
                    ybList.forEach(a -> {
                        a.setRound(a.getRound() - 1);
                    });
                } else {
                    result.addAll(dailyDudyTemplates);
                    List<DutyScheduleSet> others = ybList.stream().filter(j -> !j.getRound().equals(1)).collect(Collectors.toList());
                    others.forEach(a -> {
                        a.setRound(a.getRound() - 1);
                        DudyScheduleListVO.DudyTemplate myTemplate = dailyDudyTemplates.stream().filter(b -> b != null && b.getDudyDeptId() != null &&
                                b.getDudyDeptId().equals(a.getDeptId())).findAny().orElse(null);
                        if (myTemplate != null) {
                            long reducedCount = a.getDCount() - myTemplate.getDivisionLevelDudyNumber();
                            if (reducedCount < 0l) reducedCount = 0l;
                            a.setDCount(reducedCount);
                        }
                    });
                }
            }
        }
        return result;
    }

    @Override
    public Object detail(String id) {
        UserInfoDetailVO userInfoDetailVO = loginCompoentService.getUserInfo();
        DutyScheduleSetCustom dutyScheduleSetCustom = dutyScheduleSetCustomRepository.getById(id);
        DutyScheduleSetDetailVO dutyScheduleSetDetailVO = new DutyScheduleSetDetailVO();
        BeanUtils.copyProperties(dutyScheduleSetCustom, dutyScheduleSetDetailVO);
        dutyScheduleSetDetailVO.setMonth(Arrays.asList(dutyScheduleSetCustom.getSYearStart() + "-" + dutyScheduleSetCustom.getSMonthStart()
                , dutyScheduleSetCustom.getSYearEnd() + "-" + dutyScheduleSetCustom.getSMonthEnd()));
        DudyScheduleListVO.DailyDudy dailyDudy = new DudyScheduleListVO.DailyDudy();
        DudyScheduleListVO.HolidayAndVacationsDudy hoildayDudy = new DudyScheduleListVO.HolidayAndVacationsDudy();
        DudyScheduleListVO.ImportantDayDudy importantDudy = new DudyScheduleListVO.ImportantDayDudy();
        DudyScheduleListVO.WeekendDudy weekendDudy = new DudyScheduleListVO.WeekendDudy();
        DudyScheduleListVO dudyScheduleListVO = new DudyScheduleListVO();

        List<DutyScheduleSet> YBDeptList = dutyScheduleSetRepository.list(new LambdaQueryWrapper<DutyScheduleSet>()
                .eq(DutyScheduleSet::getSetCustomId, dutyScheduleSetCustom.getId())
                .eq(DutyScheduleSet::getSType, STypeEnum.TYPE_WB.getValue()));
        List<DudyScheduleListVO.DudyTemplate> returnDutyScheduleList = getDailyMessage(YBDeptList);
        dailyDudy.setDudyTemplate(returnDutyScheduleList);
        dudyScheduleListVO.setDailyDudy(dailyDudy);

        List<DutyScheduleSet> ZMBDeptList = dutyScheduleSetRepository.list(new LambdaQueryWrapper<DutyScheduleSet>()
                .eq(DutyScheduleSet::getSetCustomId, dutyScheduleSetCustom.getId())
                .eq(DutyScheduleSet::getSType, STypeEnum.TYPE_ZMB.getValue()));
        returnDutyScheduleList = getDailyMessage(ZMBDeptList);
        hoildayDudy.setDudyTemplate(returnDutyScheduleList);

        List<DutyScheduleSet> ZYBDeptList = dutyScheduleSetRepository.list(new LambdaQueryWrapper<DutyScheduleSet>()
                .eq(DutyScheduleSet::getSetCustomId, dutyScheduleSetCustom.getId())
                .eq(DutyScheduleSet::getSType, STypeEnum.TYPE_ZYB.getValue()));
        returnDutyScheduleList = getDailyMessage(ZYBDeptList);
        importantDudy.setDudyTemplate(returnDutyScheduleList);

        List<DutyScheduleSet> ZMDeptList = dutyScheduleSetRepository.list(new LambdaQueryWrapper<DutyScheduleSet>()
                .eq(DutyScheduleSet::getSetCustomId, dutyScheduleSetCustom.getId())
                .eq(DutyScheduleSet::getSType, STypeEnum.TYPE_ZM.getValue()));
        returnDutyScheduleList = getDailyMessage(ZMDeptList);
        weekendDudy.setDudyTemplate(returnDutyScheduleList);

        dudyScheduleListVO.setDailyDudy(dailyDudy);
        dudyScheduleListVO.setHolidayAndVacationsDudy(hoildayDudy);
        dudyScheduleListVO.setImportantDayDudy(importantDudy);
        dudyScheduleListVO.setWeekendDudy(weekendDudy);
        List<String> seTypes;
        dutyScheduleSetDetailVO.setDudyScheduleListVO(dudyScheduleListVO);
        if (userInfoDetailVO.getRole().contains("ZGGLY")) {
            seTypes = SeTypeEnum.getAllAdminCode();
        } else {
            seTypes = SeTypeEnum.getAllSubCode();
        }
        List<DutyPersonInitDetailVO> dutyPersonInitDetailVOS = new ArrayList<>();
        for (String seType : seTypes) {
            DutyPersonInitDetailVO dutyPersonInitDetailVO = new DutyPersonInitDetailVO();
            dutyPersonInitDetailVO.setSeType(seType);
            List<DutyScheduleGroupRecord> dutyScheduleGroupRecords = dutyScheduleGroupRecordRepository.list(
                    new LambdaQueryWrapper<DutyScheduleGroupRecord>()
                            .eq(DutyScheduleGroupRecord::getCustomId, dutyScheduleSetCustom.getCustomId())
                            .eq(DutyScheduleGroupRecord::getSetCustomId, dutyScheduleSetCustom.getId())
                            .eq(DutyScheduleGroupRecord::getSeType, seType));
            List<DutyPersonInitVO> dutyPersonInitVOS = dutyScheduleGroupRecords.stream().map(i -> {
                DutyPersonInitVO dutyPersonInitVO = new DutyPersonInitVO();
                dutyPersonInitVO.setDutyType(i.getDutyType());
                dutyPersonInitVO.setSeType(seType);
                dutyPersonInitVO.setGlobalSort(i.getLastPersonSort());
                dutyPersonInitVO.setPersonNo(i.getLastPersonNo());
                if (!StringUtils.isEmpty(i.getLastPersonNo())) {
                    BasePersonInfo basePersonInfo = basePersonInfoRepository.getOne(new LambdaQueryWrapper<BasePersonInfo>().eq(BasePersonInfo::getUserno, i.getLastPersonNo()), false);
                    if (basePersonInfo != null) {
                        dutyPersonInitVO.setPersonName(basePersonInfo.getUsername() + "(" + basePersonInfo.getUserno() + ")");
                    }
                }
                dutyPersonInitVO.setTypeName(SetDutyTypeEnum.getDescByCode(i.getDutyType()));
                return dutyPersonInitVO;
            }).collect(Collectors.toList());
            dutyPersonInitDetailVO.setDutyPersonInitVOS(dutyPersonInitVOS);
            dutyPersonInitDetailVOS.add(dutyPersonInitDetailVO);
        }
        dutyScheduleSetDetailVO.setDutyPersonInitVOS(dutyPersonInitDetailVOS);
        return dutyScheduleSetDetailVO;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public BaseResult delete(String id, UserInfoDetailVO userInfoDetailVO) {
        DutyScheduleSetCustom dutyScheduleSetCustom = dutyScheduleSetCustomRepository.getById(id);

        dutyScheduleSetCustomRepository.update(new LambdaUpdateWrapper<DutyScheduleSetCustom>()
                .eq(DutyScheduleSetCustom::getId, id)
                .set(DutyScheduleSetCustom::getDelFlag, DeleteFlagEnum.IS_DELETE.getValue())
                .set(DutyScheduleSetCustom::getUpdateBy, userInfoDetailVO.getUserId())
                .set(DutyScheduleSetCustom::getUpdateTime, LocalDateTime.now()));
        dutyScheduleSetRepository.update(new LambdaUpdateWrapper<DutyScheduleSet>()
                .eq(DutyScheduleSet::getSetCustomId, id)
                .set(DutyScheduleSet::getDelFlag, DeleteFlagEnum.IS_DELETE.getValue())
                .set(DutyScheduleSet::getUpdateBy, userInfoDetailVO.getUserId())
                .set(DutyScheduleSet::getUpdateTime, LocalDateTime.now()));
        dutyScheduleInfoRepository.update(new LambdaUpdateWrapper<DutyScheduleInfo>()
                .eq(DutyScheduleInfo::getSetCustomId, id)
                .set(DutyScheduleInfo::getDelFlag, DeleteFlagEnum.IS_DELETE.getValue())
                .set(DutyScheduleInfo::getUpdateBy, userInfoDetailVO.getUserId())
                .set(DutyScheduleInfo::getUpdateTime, LocalDateTime.now()));
        dutyScheduleInfoRepository.update(new LambdaUpdateWrapper<DutyScheduleInfo>()
                .eq(DutyScheduleInfo::getCustomId, dutyScheduleSetCustom.getCustomId())
                .ge(DutyScheduleInfo::getDDay, dutyScheduleSetCustom.getStartDate())
                .lt(DutyScheduleInfo::getDDay, dutyScheduleSetCustom.getEndDate().plusMonths(1)).
                        set(DutyScheduleInfo::getDelFlag, DeleteFlagEnum.IS_DELETE.getValue())
                .set(DutyScheduleInfo::getUpdateBy, userInfoDetailVO.getUserId())
                .set(DutyScheduleInfo::getUpdateTime, LocalDateTime.now()));
        dutyScheduleGroupRecordRepository.update(new LambdaUpdateWrapper<DutyScheduleGroupRecord>()
                .eq(DutyScheduleGroupRecord::getSetCustomId, id).
                        set(DutyScheduleGroupRecord::getDelFlag, DeleteFlagEnum.IS_DELETE.getValue())
                .set(DutyScheduleGroupRecord::getUpdateBy, userInfoDetailVO.getUserId())
                .set(DutyScheduleGroupRecord::getUpdateTime, LocalDateTime.now()));
        return BaseResult.ok(null, "删除成功");
    }

    @Override
    public Object reinit(String id, UserInfoDetailVO userInfoDetailVO) throws Exception {
        DutyScheduleSetDetailVO dutyScheduleSetDetailVO = (DutyScheduleSetDetailVO) detail(id);
        DutyScheduleSetSaveVO scheduleSetSaveVO = new DutyScheduleSetSaveVO();
        BeanUtils.copyProperties(dutyScheduleSetDetailVO, scheduleSetSaveVO);
        scheduleSetSaveVO.setSStatus("1");
        scheduleSetSaveVO.setSMonths(dutyScheduleSetDetailVO.getMonth());
        dutyScheduleInfoRepository.remove(new LambdaQueryWrapper<DutyScheduleInfo>()
                .eq(DutyScheduleInfo::getSetCustomId, id));
        return saveList(scheduleSetSaveVO, userInfoDetailVO, true);
    }

    @Override
    public DutyRecordDetailTotalVO dutyRecord(String customId) {
        //获取该关区id下所有的部门
        String dutyInitCustomName = systemConfig.getDutyInitCustomName();
        BaseDeptInfo tempdept = baseDeptInfoRepository.getOne(new LambdaQueryWrapper<BaseDeptInfo>()
                .eq(BaseDeptInfo::getDeptFullName, dutyInitCustomName));
        List<BaseDeptInfo> baseDeptInfos;
        if (tempdept != null && tempdept.getId() != null) {
            baseDeptInfos = baseDeptInfoRepository.list(new LambdaQueryWrapper<BaseDeptInfo>()
                    .eq(BaseDeptInfo::getParentid, tempdept.getId())
                    .orderByAsc(BaseDeptInfo::getGlobalSort));
        } else {
            baseDeptInfos = baseDeptInfoRepository.list(new LambdaQueryWrapper<BaseDeptInfo>()
                    .eq(BaseDeptInfo::getParentid, customId)
                    .orderByAsc(BaseDeptInfo::getGlobalSort));
        }
//        List<BaseDeptInfo> baseDeptInfos = baseDeptInfoRepository.list(new LambdaQueryWrapper<BaseDeptInfo>()
//                .eq(BaseDeptInfo::getParentid, customId)
////                .eq(BaseDeptInfo::getNotUseKJDept, "0")
//                .orderByAsc(BaseDeptInfo::getGlobalSort));
        List<DutyRecordDetailVO> dutyRecordDetailVOS = new ArrayList<>();
        List<DutyScheduleInfo> dutyScheduleInfos = dutyScheduleInfoRepository.list(new LambdaQueryWrapper<DutyScheduleInfo>()
                .eq(DutyScheduleInfo::getCustomId, customId)
        );
        List<BasePersonInfo> basePersonInfos = basePersonInfoRepository.list(new LambdaQueryWrapper<BasePersonInfo>()
                .eq(BasePersonInfo::getCustomId, customId));
        List<BaseDeptInfo> allDepts = guavacacheUtils.getDepts();
        for (BaseDeptInfo baseDeptInfo : baseDeptInfos) {
            List<BasePersonInfo> myPersons = baseDeptInfoService.userInDeptWith(null, baseDeptInfo, allDepts, basePersonInfos);
            DutyRecordDetailVO dutyRecordDetailVO = new DutyRecordDetailVO();
            dutyRecordDetailVO.setDeptId(baseDeptInfo.getId());
            dutyRecordDetailVO.setDeptName(baseDeptInfo.getDeptName());
            dutyRecordDetailVO.setTotalPerson(myPersons.size());
            dutyRecordDetailVO.setDutyedPerson((int) dutyScheduleInfos.stream().filter(i -> myPersons.stream().map(BasePersonInfo::getUserno)
                    .collect(Collectors.toList()).contains(i.getDUserno())).filter(distinctByKey(i -> i.getDUserno())).count());
            dutyRecordDetailVOS.add(dutyRecordDetailVO);
        }
        DutyRecordDetailTotalVO dutyRecordDetailTotalVO = new DutyRecordDetailTotalVO();
        dutyRecordDetailVOS = dutyRecordDetailVOS.stream().filter(i -> i.getDutyedPerson() > 0).collect(Collectors.toList());
        dutyRecordDetailTotalVO.setDutyRecordDetailVOList(dutyRecordDetailVOS);
        return dutyRecordDetailTotalVO;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Object saveListZS(DutyScheduleSetZSSaveVO dudyScheduleSetSaveVO, UserInfoDetailVO userInfoDetailVO, boolean b) throws Exception {
        DutyScheduleSetCustom dutyScheduleSetCustom = new DutyScheduleSetCustom();
        BeanUtils.copyProperties(dudyScheduleSetSaveVO, dutyScheduleSetCustom);
        String[] tempArray = dudyScheduleSetSaveVO.getSMonths().get(0).split("-");
        Long startYear = Long.valueOf(tempArray[0]);
        Long startMonth = Long.valueOf(tempArray[1]);
        tempArray = dudyScheduleSetSaveVO.getSMonths().get(1).split("-");
        Long endYear = Long.valueOf(tempArray[0]);
        Long endMonth = Long.valueOf(tempArray[1]);
        if (endMonth < 12) {
            endMonth = endMonth + 1;
        } else {
            endMonth = 1l;
            endYear = endYear + 1;
        }
        Long finalEndYear = endYear;
        Long finalEndMonth = endMonth;
        LambdaQueryWrapper<DutyScheduleSetCustom> queryWrapper = new LambdaQueryWrapper<DutyScheduleSetCustom>()
                .and(wrapper ->
                        wrapper.ge(DutyScheduleSetCustom::getStartDate, LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1))
                                .le(DutyScheduleSetCustom::getStartDate, LocalDate.of((int) (long) finalEndYear, (int) (long) finalEndMonth, 1).minusDays(1))
                                .or(orwrapper -> orwrapper.ge(DutyScheduleSetCustom::getEndDate, LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1))
                                        .le(DutyScheduleSetCustom::getEndDate, LocalDate.of((int) (long) finalEndYear, (int) (long) finalEndMonth, 1).minusDays(1))
                                )
                );
        queryWrapper.eq(DutyScheduleSetCustom::getCustomId, dudyScheduleSetSaveVO.getCustomId());
        if (dudyScheduleSetSaveVO.getId() != null) {
            queryWrapper.ne(DutyScheduleSetCustom::getId, dudyScheduleSetSaveVO.getId());
        }
        List<DutyScheduleSetCustom> stationInfos = dutyScheduleSetCustomRepository.list(queryWrapper);
        if (!CollectionUtils.isEmpty(stationInfos)) {
            throw new HdcException("年份和月份不能重复");
        }
        if (dudyScheduleSetSaveVO.getDudyScheduleListVO() != null) {
            //todo
            checkBodysZS(dudyScheduleSetSaveVO.getDudyScheduleListVO(), dudyScheduleSetSaveVO);
        } else {
            throw new HdcException("夜班和假日班配置至少应有一条!");
        }
        List<ParamScheduleSetting> paramScheduleSettingListTYPE_RC = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, userInfoDetailVO.getCustomscode())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_RC.getValue()));
        List<ParamScheduleSetting> paramScheduleSettingListTYPE_ZMB = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, userInfoDetailVO.getCustomscode())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_ZMB.getValue()));
        List<ParamScheduleSetting> paramScheduleSettingListTYPE_ZYB = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, userInfoDetailVO.getCustomscode())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_ZYB.getValue()));
        List<ParamScheduleSetting> paramScheduleSettingListTYPE_ZM = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, userInfoDetailVO.getCustomscode())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_ZM.getValue()));
        if (CollectionUtils.isEmpty(paramScheduleSettingListTYPE_RC)) {
            throw new HdcException("工作日班未进行排班配置!");
        }
        if (CollectionUtils.isEmpty(paramScheduleSettingListTYPE_ZMB)) {
            throw new HdcException("节假日班未进行排班配置!");
        }
        if (CollectionUtils.isEmpty(paramScheduleSettingListTYPE_ZYB)) {
            throw new HdcException("重要班未进行排班配置!");
        }
        if (CollectionUtils.isEmpty(paramScheduleSettingListTYPE_ZM)) {
            throw new HdcException("周末班未进行排班配置!");
        }
        if (StringUtils.isEmpty(dutyScheduleSetCustom.getId())) {
            if (endMonth == 1l) {
                endMonth = 12l;
                endYear = endYear - 1;
            } else {
                endMonth = endMonth - 1;
            }
            dutyScheduleSetCustom.setUpdateBy(userInfoDetailVO.getUserId());
            dutyScheduleSetCustom.setUpdateTime(LocalDateTime.now());
            dutyScheduleSetCustom.setSMonthStart(startMonth);
            dutyScheduleSetCustom.setSYearStart(startYear);
            dutyScheduleSetCustom.setSMonthEnd(endMonth);
            dutyScheduleSetCustom.setSYearEnd(endYear);
            dutyScheduleSetCustom.setStartDate(LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1));
            dutyScheduleSetCustom.setEndDate(LocalDate.of((int) (long) endYear, (int) (long) endMonth, 1));
            dutyScheduleSetCustom.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
            dutyScheduleSetCustom.setTemplateJson(JSONObject.toJSONString(dudyScheduleSetSaveVO.getDudyScheduleListVO()));
            dutyScheduleSetCustomRepository.save(dutyScheduleSetCustom);
        } else {
            if (endMonth == 1l) {
                endMonth = 12l;
                endYear = endYear - 1;
            } else {
                endMonth = endMonth - 1;
            }
            DutyScheduleSetCustom byId = dutyScheduleSetCustomRepository.getById(dutyScheduleSetCustom.getId());
            dutyScheduleSetCustom.setSMonthStart(startMonth);
            dutyScheduleSetCustom.setSYearStart(startYear);
            dutyScheduleSetCustom.setSMonthEnd(endMonth);
            dutyScheduleSetCustom.setSYearEnd(endYear);
            dutyScheduleSetCustom.setUpdateBy(userInfoDetailVO.getUserId());
            dutyScheduleSetCustom.setUpdateTime(LocalDateTime.now());
            dutyScheduleSetCustom.setStartDate(LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1));
            dutyScheduleSetCustom.setEndDate(LocalDate.of((int) (long) endYear, (int) (long) endMonth, 1));
            dutyScheduleSetCustom.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
            dutyScheduleSetCustom.setTemplateJson(JSONObject.toJSONString(dudyScheduleSetSaveVO.getDudyScheduleListVO()));
            if (byId != null){
                dutyScheduleSetCustom.setRecVersion(byId.getRecVersion());
            }
            dutyScheduleSetCustomRepository.updateById(dutyScheduleSetCustom);
            dutyScheduleSetRepository.remove(new LambdaQueryWrapper<DutyScheduleSet>()
                    .eq(DutyScheduleSet::getSetCustomId, dutyScheduleSetCustom.getId()));
        }
        List<DutyScheduleSet> YBList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(dudyScheduleSetSaveVO.getDudyScheduleListVO().getDailyDudy().getDudyTemplate())) {
            for (DudyScheduleListZGVO.DudyTemplateZG dutyScheduleSetSaveDetailVO : dudyScheduleSetSaveVO.getDudyScheduleListVO().getDailyDudy().getDudyTemplate()) {
                DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
                BeanUtils.copyProperties(dutyScheduleSetSaveDetailVO, dutyScheduleSet);
                dutyScheduleSet.setId(null);
                dutyScheduleSet.setCreateTime(LocalDateTime.now());
                dutyScheduleSet.setCreateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setSCount(0l);
                dutyScheduleSet.setDCount(0l);
                dutyScheduleSet.setZsSCount((long) dutyScheduleSetSaveDetailVO.getSLeaderCount());
                dutyScheduleSet.setZsTCount((long) dutyScheduleSetSaveDetailVO.getGLeaderCount());
                dutyScheduleSet.setZsCCount((long) dutyScheduleSetSaveDetailVO.getCLeaderCount());
                dutyScheduleSet.setZsMainCount((long) dutyScheduleSetSaveDetailVO.getMainDutyCount());
                dutyScheduleSet.setZsSubCount((long) dutyScheduleSetSaveDetailVO.getSubDutyCount());
                dutyScheduleSet.setDeptId(dutyScheduleSetSaveDetailVO.getDudyDeptId());
                dutyScheduleSet.setSDept(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setDeptName(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setUpdateTime(LocalDateTime.now());
                dutyScheduleSet.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
                dutyScheduleSet.setUpdateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setSetCustomId(dutyScheduleSetCustom.getId());
                dutyScheduleSet.setSType(STypeEnum.TYPE_WB.getValue());
                dutyScheduleSetRepository.save(dutyScheduleSet);
                YBList.add(dutyScheduleSet);
            }
        }
        List<DutyScheduleSet> ZMBList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(dudyScheduleSetSaveVO.getDudyScheduleListVO().getHolidayAndVacationsDudy().getDudyTemplate())) {
            for (DudyScheduleListZGVO.DudyTemplateZG dutyScheduleSetSaveDetailVO : dudyScheduleSetSaveVO.getDudyScheduleListVO().getHolidayAndVacationsDudy().getDudyTemplate()) {
                DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
                BeanUtils.copyProperties(dutyScheduleSetSaveDetailVO, dutyScheduleSet);
                dutyScheduleSet.setId(null);
                dutyScheduleSet.setSCount(0l);
                dutyScheduleSet.setDCount(0l);
                dutyScheduleSet.setZsSCount((long) dutyScheduleSetSaveDetailVO.getSLeaderCount());
                dutyScheduleSet.setZsTCount((long) dutyScheduleSetSaveDetailVO.getGLeaderCount());
                dutyScheduleSet.setZsCCount((long) dutyScheduleSetSaveDetailVO.getCLeaderCount());
                dutyScheduleSet.setZsMainCount((long) dutyScheduleSetSaveDetailVO.getMainDutyCount());
                dutyScheduleSet.setZsSubCount((long) dutyScheduleSetSaveDetailVO.getSubDutyCount());
                dutyScheduleSet.setDeptId(dutyScheduleSetSaveDetailVO.getDudyDeptId());
                dutyScheduleSet.setDeptName(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setSDept(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setCreateTime(LocalDateTime.now());
                dutyScheduleSet.setCreateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setUpdateTime(LocalDateTime.now());
                dutyScheduleSet.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
                dutyScheduleSet.setUpdateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setSetCustomId(dutyScheduleSetCustom.getId());
                dutyScheduleSet.setSType(STypeEnum.TYPE_ZMB.getValue());
                dutyScheduleSetRepository.save(dutyScheduleSet);
                ZMBList.add(dutyScheduleSet);
            }
        }
        List<DutyScheduleSet> ZYBList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(dudyScheduleSetSaveVO.getDudyScheduleListVO().getImportantDayDudy().getDudyTemplate())) {
            for (DudyScheduleListZGVO.DudyTemplateZG dutyScheduleSetSaveDetailVO : dudyScheduleSetSaveVO.getDudyScheduleListVO().getImportantDayDudy().getDudyTemplate()) {
                DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
                BeanUtils.copyProperties(dutyScheduleSetSaveDetailVO, dutyScheduleSet);
                dutyScheduleSet.setId(null);
                dutyScheduleSet.setSCount(0l);
                dutyScheduleSet.setDCount(0l);
                dutyScheduleSet.setZsSCount((long) dutyScheduleSetSaveDetailVO.getSLeaderCount());
                dutyScheduleSet.setZsTCount((long) dutyScheduleSetSaveDetailVO.getGLeaderCount());
                dutyScheduleSet.setZsCCount((long) dutyScheduleSetSaveDetailVO.getCLeaderCount());
                dutyScheduleSet.setZsMainCount((long) dutyScheduleSetSaveDetailVO.getMainDutyCount());
                dutyScheduleSet.setZsSubCount((long) dutyScheduleSetSaveDetailVO.getSubDutyCount());
                dutyScheduleSet.setSDept(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setDeptId(dutyScheduleSetSaveDetailVO.getDudyDeptId());
                dutyScheduleSet.setDeptName(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setCreateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setDeptId(dutyScheduleSet.getDeptId());
                dutyScheduleSet.setUpdateTime(LocalDateTime.now());
                dutyScheduleSet.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
                dutyScheduleSet.setUpdateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setSetCustomId(dutyScheduleSetCustom.getId());
                dutyScheduleSet.setSType(STypeEnum.TYPE_ZYB.getValue());
                dutyScheduleSetRepository.save(dutyScheduleSet);
                ZYBList.add(dutyScheduleSet);
            }
        }
        List<DutyScheduleSet> ZMList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(dudyScheduleSetSaveVO.getDudyScheduleListVO().getWeekendDudy().getDudyTemplate())) {
            for (DudyScheduleListZGVO.DudyTemplateZG dutyScheduleSetSaveDetailVO : dudyScheduleSetSaveVO.getDudyScheduleListVO().getWeekendDudy().getDudyTemplate()) {
                DutyScheduleSet dutyScheduleSet = new DutyScheduleSet();
                BeanUtils.copyProperties(dutyScheduleSetSaveDetailVO, dutyScheduleSet);
                dutyScheduleSet.setId(null);
                dutyScheduleSet.setSCount(0l);
                dutyScheduleSet.setDCount(0l);
                dutyScheduleSet.setZsSCount((long) dutyScheduleSetSaveDetailVO.getSLeaderCount());
                dutyScheduleSet.setZsTCount((long) dutyScheduleSetSaveDetailVO.getGLeaderCount());
                dutyScheduleSet.setZsCCount((long) dutyScheduleSetSaveDetailVO.getCLeaderCount());
                dutyScheduleSet.setZsMainCount((long) dutyScheduleSetSaveDetailVO.getMainDutyCount());
                dutyScheduleSet.setZsSubCount((long) dutyScheduleSetSaveDetailVO.getSubDutyCount());
                dutyScheduleSet.setSDept(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setDeptId(dutyScheduleSetSaveDetailVO.getDudyDeptId());
                dutyScheduleSet.setDeptName(dutyScheduleSetSaveDetailVO.getDudyDept());
                dutyScheduleSet.setCreateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setDeptId(dutyScheduleSet.getDeptId());
                dutyScheduleSet.setUpdateTime(LocalDateTime.now());
                dutyScheduleSet.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
                dutyScheduleSet.setUpdateBy(userInfoDetailVO.getUserId());
                dutyScheduleSet.setSetCustomId(dutyScheduleSetCustom.getId());
                dutyScheduleSet.setSType(STypeEnum.TYPE_ZM.getValue());
                dutyScheduleSetRepository.save(dutyScheduleSet);
                ZMList.add(dutyScheduleSet);
            }
        }
        dutyScheduleGroupRecordRepository.remove(new LambdaQueryWrapper<DutyScheduleGroupRecord>()
                .eq(DutyScheduleGroupRecord::getCustomId, dudyScheduleSetSaveVO.getCustomId())
                .eq(DutyScheduleGroupRecord::getSetCustomId, dudyScheduleSetSaveVO.getId()));
        List<DutyPersonInitVO> dutyScheduleSetDetailVOS = dudyScheduleSetSaveVO.getDutyPersonInitVOS();
        List<DutyScheduleGroupRecord> dutyScheduleGroupRecords = new ArrayList<>();
        for (DutyPersonInitVO dutyScheduleSetDetailVO : dutyScheduleSetDetailVOS) {
            DutyScheduleGroupRecord dutyScheduleGroupRecord = new DutyScheduleGroupRecord();
            dutyScheduleGroupRecord.setCustomId(dudyScheduleSetSaveVO.getCustomId());
            dutyScheduleGroupRecord.setDutyType(dutyScheduleSetDetailVO.getDutyType());
            dutyScheduleGroupRecord.setSeType(dutyScheduleSetDetailVO.getSeType());
//                dutyScheduleGroupRecord.setLastPersonName(dutyScheduleSetDetailVO.getPersonName());
            dutyScheduleGroupRecord.setLastPersonNo(dutyScheduleSetDetailVO.getPersonNo());
            dutyScheduleGroupRecord.setLastPersonSort(dutyScheduleSetDetailVO.getGlobalSort());
            dutyScheduleGroupRecord.setDelFlag("0");
            dutyScheduleGroupRecord.setCreateTime(LocalDateTime.now());
            dutyScheduleGroupRecord.setSetCustomId(dutyScheduleSetCustom.getId());
            dutyScheduleGroupRecords.add(dutyScheduleGroupRecord);
        }
        if (SStatusEnum.TYPE_SUBMIT.getValue().equals(dudyScheduleSetSaveVO.getSStatus())) {
            createPersonsZS(dudyScheduleSetSaveVO, YBList, ZMBList, ZYBList, ZMList, dutyScheduleSetCustom.getId(),
                    startMonth, startYear, endYear, endMonth, true, dudyScheduleSetSaveVO.getDutyPersonInitVOS(),
                    dutyScheduleGroupRecords);
        }

        dutyScheduleGroupRecordRepository.saveBatch(dutyScheduleGroupRecords);
        return true;
    }

    private void createPersonsZS(DutyScheduleSetZSSaveVO dudyScheduleSetSaveVO, List<DutyScheduleSet> YBList, List<DutyScheduleSet> ZMBList, List<DutyScheduleSet> ZYBList, List<DutyScheduleSet> ZMList, String id, Long sMonth, Long sYear, Long endYear, Long endMonth, boolean INIT, List<DutyPersonInitVO> dutyPersonInitDetailVOS, List<DutyScheduleGroupRecord> dutyScheduleGroupRecords) throws Exception {
        List<DutyScheduleInfo> dutyScheduleInfos = new ArrayList<>();
        BaseDeptInfo custom = baseDeptInfoRepository.getById(dudyScheduleSetSaveVO.getCustomId());
        if (endMonth < 12) {
            endMonth = endMonth + 1;
        } else {
            endMonth = 1l;
            endYear = endYear + 1;
        }
        List<ParamHolidays> holidays = paramHolidaysRepository.list(new LambdaQueryWrapper<ParamHolidays>()
                .ge(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1))
                .lt(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) endYear, (int) (long) endMonth, 1))
                .eq(ParamHolidays::getCustomId, dudyScheduleSetSaveVO.getCustomId())
                .eq(ParamHolidays::getHolidayType, HolidaysEnum.HOLIDAY.getValue()));
        List<ParamHolidays> importantDays = paramHolidaysRepository.list(new LambdaQueryWrapper<ParamHolidays>()
                .ge(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1))
                .lt(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) endYear, (int) (long) endMonth, 1))
                .eq(ParamHolidays::getCustomId, dudyScheduleSetSaveVO.getCustomId())
                .eq(ParamHolidays::getHolidayType, HolidaysEnum.IMPORTANT_PERIOD.getValue()));
        List<ParamHolidays> exhangeDays = paramHolidaysRepository.list(new LambdaQueryWrapper<ParamHolidays>()
                .ge(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) sYear, (int) (long) sMonth, 1))
                .lt(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) endYear, (int) (long) endMonth, 1))
                .eq(ParamHolidays::getCustomId, dudyScheduleSetSaveVO.getCustomId())
                .eq(ParamHolidays::getHolidayType, HolidaysEnum.HOLIDAY_EXCHANGE.getValue()));
        dutyScheduleInfos = getParents(dutyScheduleInfos);
        //如果
        //获取该关区id下所有的部门
        String dutyInitCustomName = systemConfig.getDutyInitCustomName();
        BaseDeptInfo baseDeptInfo = baseDeptInfoRepository.getOne(new LambdaQueryWrapper<BaseDeptInfo>()
                .eq(BaseDeptInfo::getDeptFullName, dutyInitCustomName));
        List<BaseDeptInfo> baseDeptInfos;
        if (baseDeptInfo != null && baseDeptInfo.getId() != null) {
            baseDeptInfos = baseDeptInfoRepository.list(new LambdaQueryWrapper<BaseDeptInfo>()
                    .eq(BaseDeptInfo::getParentid, baseDeptInfo.getId())
                    .orderByAsc(BaseDeptInfo::getGlobalSort));
        } else {
            baseDeptInfos = baseDeptInfoRepository.list(new LambdaQueryWrapper<BaseDeptInfo>()
                    .eq(BaseDeptInfo::getParentid, dudyScheduleSetSaveVO.getCustomId())
                    .orderByAsc(BaseDeptInfo::getGlobalSort));
        }
        List<BaseDeptInfo> allDepts = baseDeptInfoRepository.list(new LambdaQueryWrapper<BaseDeptInfo>()
                .eq(BaseDeptInfo::getCustomId, dudyScheduleSetSaveVO.getCustomId())
        );
        List<ParamGroupDuty> paramGroupDuties = paramGroupDutyRepository.list(new LambdaQueryWrapper<ParamGroupDuty>()
                .eq(ParamGroupDuty::getCustomId, custom.getId()));
        List<ParamGroupDuty> dailysDutys = paramGroupDuties.stream().filter(i -> "4".equals(i.getSeType()) && "1".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            log.info("工作日署领导");
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "1".equals(j.getDutyType()) && "4".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "4", "1");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setSLeaderCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = YBList.stream().map(j -> j.getZsSCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesFosSLeader(YBList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }

                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSS(i, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getDetailDayForZSS(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, YBList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("4") && j.getDutyType().contains("1"))
                                    .findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }

                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "4".equals(i.getSeType()) && "4".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            log.info("周末署领导");
            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "4".equals(j.getDutyType()) && "4".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "4", "4");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setSLeaderCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = ZMList.stream().map(j -> j.getZsSCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesFosSLeader(ZMList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSS(i, ZMList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getWeekendDayForZSS(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, ZMList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("4") && j.getDutyType().contains("4")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "4".equals(i.getSeType()) && "2".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {

            log.info("42");

            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "2".equals(j.getDutyType()) && "4".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "4", "2");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setSLeaderCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = ZMBList.stream().map(j -> j.getZsSCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesFosSLeader(ZMBList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSS(i, ZMBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getHoildayForZSS(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, ZMBList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("4") && j.getDutyType().contains("2")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "4".equals(i.getSeType()) && "3".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            //夜班 科员
            log.info("43");

            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "3".equals(j.getDutyType()) && "4".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "4", "3");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setSLeaderCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = ZYBList.stream().map(j -> j.getZsSCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesFosSLeader(ZYBList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSS(i, ZYBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getImportDayForZSS(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, ZYBList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("4") && j.getDutyType().contains("3")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "7".equals(i.getSeType()) && "1".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            log.info("71");

            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "1".equals(j.getDutyType()) && "7".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "7", "1");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setMainDutyCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = YBList.stream().map(j -> j.getZsMainCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForMainDuty(YBList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSMain(i, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getDetailDayForZSMain(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, YBList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("7") && j.getDutyType().contains("1")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "7".equals(i.getSeType()) && "4".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            log.info("值班74");

            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "4".equals(j.getDutyType()) && "7".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "7", "4");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setMainDutyCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = ZMList.stream().map(j -> j.getZsMainCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForMainDuty(ZMList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSMain(i, ZMList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getWeekendDayForZSMain(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, ZMList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("7") && j.getDutyType().contains("4")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "7".equals(i.getSeType()) && "2".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            log.info("值班72");

            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "2".equals(j.getDutyType()) && "7".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "7", "2");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setMainDutyCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = ZMBList.stream().map(j -> j.getZsMainCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForMainDuty(ZMBList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSMain(i, ZMBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getHoildayForZSMain(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, ZMBList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("7") && j.getDutyType().contains("2")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "7".equals(i.getSeType()) && "3".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            log.info("值班73");
            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "3".equals(j.getDutyType()) && "7".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "7", "3");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setMainDutyCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = ZYBList.stream().map(j -> j.getZsMainCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForMainDuty(ZYBList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSMain(i, ZYBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getImportDayForZSMain(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, ZYBList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("7") && j.getDutyType().contains("3")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }


        dailysDutys = paramGroupDuties.stream().filter(i -> "8".equals(i.getSeType()) && "1".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "1".equals(j.getDutyType()) && "8".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "8", "1");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setSubDutyCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = YBList.stream().map(j -> j.getZsSubCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForSubDuty(YBList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSSub(i, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getDetailDayForZSSub(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, YBList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("8") && j.getDutyType().contains("1")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "8".equals(i.getSeType()) && "4".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "4".equals(j.getDutyType()) && "8".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "8", "4");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setSubDutyCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = ZMList.stream().map(j -> j.getZsSubCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForSubDuty(ZMList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSSub(i, ZMList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getWeekendDayForZSSub(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, ZMList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("8") && j.getDutyType().contains("4")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "8".equals(i.getSeType()) && "2".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "2".equals(j.getDutyType()) && "8".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "8", "2");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setSubDutyCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = ZMBList.stream().map(j -> j.getZsSubCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForSubDuty(ZMBList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSSub(i, ZMBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getHoildayForZSSub(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, ZMBList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("8") && j.getDutyType().contains("2")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "8".equals(i.getSeType()) && "3".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "3".equals(j.getDutyType()) && "8".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "8", "3");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setSubDutyCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = ZYBList.stream().map(j -> j.getZsSubCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForSubDuty(ZYBList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSSub(i, ZYBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getImportDayForZSSub(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, ZYBList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("8") && j.getDutyType().contains("3")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }


        dailysDutys = paramGroupDuties.stream().filter(i -> "6".equals(i.getSeType()) && "1".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "1".equals(j.getDutyType()) && "6".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "6", "1");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setCLeaderCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = YBList.stream().map(j -> j.getZsCCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForCLeader(YBList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSC(i, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getDetailDayForZSC(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, YBList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("6") && j.getDutyType().contains("1")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "6".equals(i.getSeType()) && "4".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "4".equals(j.getDutyType()) && "6".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "6", "4");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setCLeaderCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = ZMList.stream().map(j -> j.getZsCCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForCLeader(ZMList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSC(i, ZMList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getWeekendDayForZSC(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, ZMList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("6") && j.getDutyType().contains("4")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "6".equals(i.getSeType()) && "2".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "2".equals(j.getDutyType()) && "6".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "6", "2");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setCLeaderCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = ZMBList.stream().map(j -> j.getZsCCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForCLeader(ZMBList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSC(i, ZMBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getHoildayForZSC(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, ZMBList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("6") && j.getDutyType().contains("2")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "6".equals(i.getSeType()) && "3".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "3".equals(j.getDutyType()) && "6".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "6", "3");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setCLeaderCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = ZYBList.stream().map(j -> j.getZsCCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForCLeader(ZYBList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZSC(i, ZYBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getImportDayForZSC(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, ZYBList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("6") && j.getDutyType().contains("3")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }


        dailysDutys = paramGroupDuties.stream().filter(i -> "5".equals(i.getSeType()) && "1".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "1".equals(j.getDutyType()) && "5".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "5", "1");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setGLeaderCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = YBList.stream().map(j -> j.getZsTCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForTLeader(YBList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZST(i, YBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getDetailDayForZST(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, YBList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("5") && j.getDutyType().contains("1")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "5".equals(i.getSeType()) && "4".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "4".equals(j.getDutyType()) && "5".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "5", "4");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setGLeaderCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = ZMList.stream().map(j -> j.getZsTCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForTLeader(ZMList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZST(i, ZMList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getWeekendDayForZST(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, ZMList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("5") && j.getDutyType().contains("4")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "5".equals(i.getSeType()) && "2".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "2".equals(j.getDutyType()) && "5".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "5", "2");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setGLeaderCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = ZMBList.stream().map(j -> j.getZsTCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForTLeader(ZMBList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZST(i, ZMBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getHoildayForZST(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, ZMBList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("5") && j.getDutyType().contains("2")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "5".equals(i.getSeType()) && "3".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            //夜班 科员
            DutyPersonInitVO dutyPersonInitVO = dutyPersonInitDetailVOS.stream().filter(j -> "3".equals(j.getDutyType()) && "5".equals(j.getSeType())).findAny().orElse(null);
            List<BasePersonInfo> persons = basePersonInfoRepository.getPersonInCustomGroup(custom.getId(), "5", "3");
            List<DudyScheduleListZGVO.DudyTemplateZG> deptTemplates = new ArrayList<>();
            for (BaseDeptInfo j : baseDeptInfos) {
                DudyScheduleListZGVO.DudyTemplateZG dudyTemplate = new DudyScheduleListZGVO.DudyTemplateZG();
                List<BasePersonInfo> thisDept = baseDeptInfoService.getBasePersonInfosInThisDept(persons, j, allDepts);
                thisDept = thisDept.stream().sorted(PersonCompareUtil.comparePersonForSort()).collect(Collectors.toList());
                dudyTemplate.setGLeaderCount(thisDept.size());
                dudyTemplate.setDudyDeptId(j.getId());
                dudyTemplate.setDudyDept(j.getDeptName());
                dudyTemplate.setSort(j.getGlobalSort());
                dudyTemplate.setThisDeptPerson(thisDept);
                deptTemplates.add(dudyTemplate);
            }
            long totalCount = ZYBList.stream().map(j -> j.getZsTCount()).reduce((a, b) -> a + b).orElse(0l);
            if (totalCount != 0) {
                List<DudyScheduleListZGVO.DudyTemplateZG> dudyTemplates = createLineTemplatesForTLeader(ZYBList, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                for (int i = 1; i <= totalCount; i++) {

                    if (CollectionUtils.isEmpty(persons)) {
                        throw new Exception("无法获取人员，请确认配置的值班群组是否为空群组" + "3" + "1");
                    }
                    if (dutyPersonInitVO.getPersonNo() == null) {
                        throw new Exception("无法获取人员，请确认配置了值班起始人员" + "3" + "1");
                    }
                    BasePersonInfo tempPerson = new BasePersonInfo();
                    tempPerson.setGlobalSort(dutyPersonInitVO.getGlobalSort());
            //        persons = persons.stream().filter(j -> PersonCompareUtil.comparePersonForSort().compare(j, tempPerson) >= 0).collect(Collectors.toList());
                    DutyScheduleSet temp = getDayOfYBListForZST(i, ZYBList, dudyTemplates, null, dutyPersonInitVO, persons, allDepts, baseDeptInfos, deptTemplates);
                    DutyScheduleInfo dutyScheduleInfo = new DutyScheduleInfo();
                    dutyScheduleInfo.setSId(temp.getId());
                    dutyScheduleInfo.setDType("1");
                    dutyScheduleInfo.setSType("3");
                    dutyScheduleInfo.setDDeptname(temp.getDeptName());
                    dutyScheduleInfo.setDDept(temp.getDeptId());
                    List<DutyScheduleInfo> scheduleInfos = getImportDayForZST(sYear, sMonth, i, holidays, importantDays, custom, exhangeDays, dudyTemplates, ZYBList, allDepts, baseDeptInfos, deptTemplates, persons, dutyPersonInitVO);
                    if (!CollectionUtils.isEmpty(scheduleInfos)) {
                        dutyScheduleInfos.addAll(scheduleInfos);
                        scheduleInfos = scheduleInfos.stream().sorted(Comparator.comparing(j -> j.getDEndDateTime())).collect(Collectors.toList());
                        if (i == totalCount) {
                            dutyScheduleGroupRecords.stream().filter(j -> j.getSeType().contains("5") && j.getDutyType().contains("3")).findAny().orElse(new DutyScheduleGroupRecord())
                                    .setFinalPersonName(scheduleInfos.get(scheduleInfos.size() - 1).getDUsername())
                                    .setFinalPersonNo(scheduleInfos.get(scheduleInfos.size() - 1).getDUserno())
                                    .setFinalPersonSort(scheduleInfos.get(scheduleInfos.size() - 1).getGlobalSort());
                        }
                    }
                }
            }
        }


        //周末版 关领导,处领导，科领导
        //节假日版 关领导,处领导，科领导

        //重要时期班版 关领导,处领导，科领导
        List<ParamDuty> ditys = paramDutyRepository.list(new LambdaQueryWrapper<ParamDuty>()
                .eq(ParamDuty::getDDept, custom.getId()));
        Map<String, ParamDuty> paramDutyMap = ditys.stream().collect(Collectors.toMap(i -> i.getId(), i -> i));
        Map<String, BaseDeptInfo> baseDeptInfoMap = allDepts.stream().collect(Collectors.toMap(i -> i.getId(), i -> i));
        dutyScheduleInfos = dutyScheduleInfos.stream().map(j -> {
            DutyScheduleInfo i = new DutyScheduleInfo();
            BeanUtils.copyProperties(j, i);
            i.setId(null);
            i.setSetCustomId(id);
            i.setCreateTime(LocalDateTime.now());
            i.setUpdateTime(LocalDateTime.now());
            i.setCreateBy("-1");
            i.setUpdateBy("-1");
            i.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
            if (i.getDDeptname() == null && !StringUtils.isEmpty(i.getDDept())) {
                BaseDeptInfo temp = baseDeptInfoMap.get(i.getDDept());
                if (baseDeptInfo != null) {
                    i.setDDeptname(temp.getDeptName()
                    );
                }
            }
            i.setCustomId(custom.getId());
            i.setCustomName(custom.getDeptName());
            ParamDuty paramDuty = paramDutyMap.get(i.getDutyTimesId());
            if (paramDuty != null&&!StringUtils.isEmpty(paramDuty.getId())) {
                if (paramDuty.getDStartTime().compareTo(paramDuty.getDEndTime()) < 0) {
                    i.setDStartDateTime(i.getDDay().atTime(paramDuty.getDStartTime()));
                    i.setDEndDateTime(i.getDDay().atTime(paramDuty.getDEndTime()));
                } else {
                    i.setDStartDateTime(i.getDDay().atTime(paramDuty.getDStartTime()));
                    i.setDEndDateTime(i.getDDay().plusDays(1l).atTime(paramDuty.getDEndTime()));
                }
            }
//            switch (i.getDUserjob()){
//                case "1":
//                    i.setDutyType("7");
//                    break;
//                case "2":
//                    i.setDutyType("6");
//            }
            return i;

        }).collect(Collectors.toList());
        dutyScheduleInfoRepository.saveBatch(dutyScheduleInfos);
        List<DutySignInfo> dutySignInfos = new ArrayList<>();
        for (DutyScheduleInfo scheduleInfo : dutyScheduleInfos) {
            if (!org.apache.commons.lang.StringUtils.isEmpty(scheduleInfo.getDUserno())) {
                DutySignInfo dutySignInfo = new DutySignInfo();
                dutySignInfo.setDId(scheduleInfo.getId());
                dutySignInfo.setCreateBy("sys");
                dutySignInfo.setCreateTime(LocalDateTime.now());
                dutySignInfo.setUpdateBy("sys");
                dutySignInfo.setUpdateTime(LocalDateTime.now());
                dutySignInfo.setDelFlag(DeleteFlagEnum.NOT_DELETE.getValue());
                dutySignInfos.add(dutySignInfo);
            }
        }
        if (!CollectionUtils.isEmpty(dutySignInfos)) {
            dutySignInfoRepository.saveBatch(dutySignInfos);
        }

    }

    static <T> Predicate<T> distinctByKey(Function<? super T, ?> ketExtractor) {
        Map<Object, Boolean> seen = new ConcurrentHashMap<>();
        return t -> seen.putIfAbsent(ketExtractor.apply(t), Boolean.TRUE) == null;
    }

    private List<DudyScheduleListVO.DudyTemplate> getDailyMessage(List<DutyScheduleSet> ybDeptList) {
        List<DudyScheduleListVO.DudyTemplate> dudyTemplates = ybDeptList.stream().map(i -> {
            DudyScheduleListVO.DudyTemplate dudyTemplate = new DudyScheduleListVO.DudyTemplate();
            dudyTemplate.setDudyDeptId(i.getDeptId());
            dudyTemplate.setDudyDept(i.getSDept());
            dudyTemplate.setSectionLevelDudyNumber((int) (long) i.getSCount());
            dudyTemplate.setDivisionLevelDudyNumber(i.getDCount() != null ? (int) (long) i.getDCount() : 0);
            dudyTemplate.setZsSCount(i.getZsSCount());
            dudyTemplate.setZsTCount(i.getZsTCount());
            dudyTemplate.setZsCCount(i.getZsCCount());
            dudyTemplate.setZsMainCount(i.getZsMainCount());
            dudyTemplate.setZsSubCount(i.getZsSubCount());
            dudyTemplate.setRound(i.getRound());
            return dudyTemplate;
        }).collect(Collectors.toList());
        return dudyTemplates;
    }

    private void checkBodysZS(DudyScheduleListZGVO dudyScheduleSetSaveVO, DutyScheduleSetZSSaveVO scheduleSetSaveVO) throws Exception {
        String[] tempArray = scheduleSetSaveVO.getSMonths().get(0).split("-");
        Long startYear = Long.valueOf(tempArray[0]);
        Long startMonth = Long.valueOf(tempArray[1]);
        tempArray = scheduleSetSaveVO.getSMonths().get(1).split("-");
        Long endYear = Long.valueOf(tempArray[0]);
        Long endMonth = Long.valueOf(tempArray[1]);
        if (endMonth < 12) {
            endMonth = endMonth + 1;
        } else {
            endMonth = 1l;
            endYear = endYear + 1;
        }
        List<ParamHolidays> holidays = paramHolidaysRepository.list(new LambdaQueryWrapper<ParamHolidays>()
                .ge(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1))
                .lt(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) endYear, (int) (long) endMonth, 1))
                .eq(ParamHolidays::getCustomId, scheduleSetSaveVO.getCustomId())
                .eq(ParamHolidays::getHolidayType, HolidaysEnum.HOLIDAY.getValue()));
        List<ParamHolidays> importantDays = paramHolidaysRepository.list(new LambdaQueryWrapper<ParamHolidays>()
                .ge(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1))
                .lt(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) endYear, (int) (long) endMonth, 1))
                .eq(ParamHolidays::getCustomId, scheduleSetSaveVO.getCustomId())
                .eq(ParamHolidays::getHolidayType, HolidaysEnum.IMPORTANT_PERIOD.getValue()));
        List<ParamHolidays> hoildayExchanges = paramHolidaysRepository.list(new LambdaQueryWrapper<ParamHolidays>()
                .ge(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1))
                .lt(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) endYear, (int) (long) endMonth, 1))
                .eq(ParamHolidays::getCustomId, scheduleSetSaveVO.getCustomId())
                .eq(ParamHolidays::getHolidayType, HolidaysEnum.HOLIDAY_EXCHANGE.getValue()));
        //24.08.02
        List<ParamScheduleSetting> rcSetting = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, scheduleSetSaveVO.getCustomId())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_RC.getValue()));
        List<ParamScheduleSetting> zmbSetting = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, scheduleSetSaveVO.getCustomId())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_ZMB.getValue()));
        List<ParamScheduleSetting> zybSetting = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, scheduleSetSaveVO.getCustomId())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_ZYB.getValue()));
        List<ParamScheduleSetting> zmSetting = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, scheduleSetSaveVO.getCustomId())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_ZM.getValue()));
        Integer hoilDayCount = holidays.size() * zmbSetting.size();
        Integer importantCount = importantDays.size() * zybSetting.size();
        Integer commonCount = DateUtil.getCommonCount(startYear, startMonth, endYear, endMonth, holidays, importantDays, hoildayExchanges, rcSetting, zmSetting);
        Integer weekendCount = DateUtil.getWeekendCount(startYear, startMonth, endYear, endMonth, holidays, importantDays, hoildayExchanges, rcSetting, zmSetting);
        //24.08.02
        if (CollectionUtils.isEmpty(dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate())) {
            throw new Exception("工作日班次不能为空");
        }
        if (CollectionUtils.isEmpty(dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate())) {
            throw new Exception("节假日班次不能为空");
        }
        if (CollectionUtils.isEmpty(dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate())) {
            throw new Exception("重要事情班次不能为空");
        }
        List<ParamGroupDuty> paramGroupDuties = paramGroupDutyRepository.list(new LambdaQueryWrapper<ParamGroupDuty>()
                .eq(ParamGroupDuty::getCustomId, scheduleSetSaveVO.getCustomId()));
        List<ParamGroupDuty> dailysDutys = paramGroupDuties.stream().filter(i -> "4".equals(i.getSeType()) && "1".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!commonCount.equals(dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate().stream().map(i -> i.getSLeaderCount() == null ? 0 : i.getSLeaderCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("工作日班署领导应有" + commonCount + "人次，实有" + dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate().stream().map(i -> i.getSLeaderCount() == null ? 0 : i.getSLeaderCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }
        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "5".equals(i.getSeType()) && "1".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!commonCount.equals(dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate().stream().map(i -> i.getGLeaderCount() == null ? 0 : i.getGLeaderCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("工作日班司局领导级应有" + commonCount + "人次，实有" + dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate().stream().map(i -> i.getGLeaderCount() == null ? 0 : i.getGLeaderCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }

        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "6".equals(i.getSeType()) && "1".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!commonCount.equals(dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate().stream().map(i -> i.getCLeaderCount() == null ? 0 : i.getCLeaderCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("工作日班处领导级应有" + commonCount + "人次，实有" + dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate().stream().map(i -> i.getCLeaderCount() == null ? 0 : i.getCLeaderCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }

        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "7".equals(i.getSeType()) && "1".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!commonCount.equals(dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate().stream().map(i -> i.getMainDutyCount() == null ? 0 : i.getMainDutyCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("工作日班主排班员应有" + commonCount + "人次，实有" + dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate().stream().map(i -> i.getMainDutyCount() == null ? 0 : i.getMainDutyCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }

        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "8".equals(i.getSeType()) && "1".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!commonCount.equals(dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate().stream().map(i -> i.getSubDutyCount() == null ? 0 : i.getSubDutyCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("工作日班副排班员应有" + commonCount + "人次，实有" + dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate().stream().map(i -> i.getSubDutyCount() == null ? 0 : i.getSubDutyCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "4".equals(i.getSeType()) && "4".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!weekendCount.equals(dudyScheduleSetSaveVO.getWeekendDudy().getDudyTemplate().stream().map(i -> i.getSLeaderCount() == null ? 0 : i.getSLeaderCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("周末班署领导应有" + weekendCount + "人次，实有" + dudyScheduleSetSaveVO.getWeekendDudy().getDudyTemplate().stream().map(i -> i.getSLeaderCount() == null ? 0 : i.getSLeaderCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }
        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "5".equals(i.getSeType()) && "4".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!weekendCount.equals(dudyScheduleSetSaveVO.getWeekendDudy().getDudyTemplate().stream().map(i -> i.getGLeaderCount() == null ? 0 : i.getGLeaderCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("周末班司局领导级应有" + weekendCount + "人次，实有" + dudyScheduleSetSaveVO.getWeekendDudy().getDudyTemplate().stream().map(i -> i.getGLeaderCount() == null ? 0 : i.getGLeaderCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }

        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "6".equals(i.getSeType()) && "4".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!weekendCount.equals(dudyScheduleSetSaveVO.getWeekendDudy().getDudyTemplate().stream().map(i -> i.getCLeaderCount() == null ? 0 : i.getCLeaderCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("周末班处领导级应有" + weekendCount + "人次，实有" + dudyScheduleSetSaveVO.getWeekendDudy().getDudyTemplate().stream().map(i -> i.getCLeaderCount() == null ? 0 : i.getCLeaderCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }

        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "7".equals(i.getSeType()) && "4".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!weekendCount.equals(dudyScheduleSetSaveVO.getWeekendDudy().getDudyTemplate().stream().map(i -> i.getMainDutyCount() == null ? 0 : i.getMainDutyCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("周末班主排班员应有" + weekendCount + "人次，实有" + dudyScheduleSetSaveVO.getWeekendDudy().getDudyTemplate().stream().map(i -> i.getMainDutyCount() == null ? 0 : i.getMainDutyCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }

        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "8".equals(i.getSeType()) && "4".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!weekendCount.equals(dudyScheduleSetSaveVO.getWeekendDudy().getDudyTemplate().stream().map(i -> i.getSubDutyCount() == null ? 0 : i.getSubDutyCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("周末班副排班员应有" + weekendCount + "人次，实有" + dudyScheduleSetSaveVO.getWeekendDudy().getDudyTemplate().stream().map(i -> i.getSubDutyCount() == null ? 0 : i.getSubDutyCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "4".equals(i.getSeType()) && "2".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!hoilDayCount.equals(dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate().stream().map(i -> i.getSLeaderCount() == null ? 0 : i.getSLeaderCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("节假日班署领导应有" + hoilDayCount + "人次，实有" + dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate().stream().map(i -> i.getSLeaderCount() == null ? 0 : i.getSLeaderCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }
        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "5".equals(i.getSeType()) && "2".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!hoilDayCount.equals(dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate().stream().map(i -> i.getGLeaderCount() == null ? 0 : i.getGLeaderCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("节假日班司局领导级应有" + hoilDayCount + "人次，实有" + dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate().stream().map(i -> i.getGLeaderCount() == null ? 0 : i.getGLeaderCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }

        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "6".equals(i.getSeType()) && "2".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!hoilDayCount.equals(dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate().stream().map(i -> i.getCLeaderCount() == null ? 0 : i.getCLeaderCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("节假日班处领导级应有" + hoilDayCount + "人次，实有" + dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate().stream().map(i -> i.getCLeaderCount() == null ? 0 : i.getCLeaderCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }

        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "7".equals(i.getSeType()) && "2".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!hoilDayCount.equals(dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate().stream().map(i -> i.getMainDutyCount() == null ? 0 : i.getMainDutyCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("节假日班主排班员应有" + hoilDayCount + "人次，实有" + dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate().stream().map(i -> i.getMainDutyCount() == null ? 0 : i.getMainDutyCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }

        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "8".equals(i.getSeType()) && "2".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!hoilDayCount.equals(dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate().stream().map(i -> i.getSubDutyCount() == null ? 0 : i.getSubDutyCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("节假日班副排班员应有" + hoilDayCount + "人次，实有" + dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate().stream().map(i -> i.getSubDutyCount() == null ? 0 : i.getSubDutyCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }
        }

        dailysDutys = paramGroupDuties.stream().filter(i -> "4".equals(i.getSeType()) && "3".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!importantCount.equals(dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate().stream().map(i -> i.getSLeaderCount() == null ? 0 : i.getSLeaderCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("重要日班署领导应有" + importantCount + "人次，实有" + dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate().stream().map(i -> i.getSLeaderCount() == null ? 0 : i.getSLeaderCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }
        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "5".equals(i.getSeType()) && "3".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!importantCount.equals(dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate().stream().map(i -> i.getGLeaderCount() == null ? 0 : i.getGLeaderCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("重要日班司局领导级应有" + importantCount + "人次，实有" + dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate().stream().map(i -> i.getGLeaderCount() == null ? 0 : i.getGLeaderCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }

        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "6".equals(i.getSeType()) && "3".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!importantCount.equals(dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate().stream().map(i -> i.getCLeaderCount() == null ? 0 : i.getCLeaderCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("重要日班处领导级应有" + importantCount + "人次，实有" + dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate().stream().map(i -> i.getCLeaderCount() == null ? 0 : i.getCLeaderCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }

        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "7".equals(i.getSeType()) && "3".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!importantCount.equals(dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate().stream().map(i -> i.getMainDutyCount() == null ? 0 : i.getMainDutyCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("重要日班主排班员应有" + importantCount + "人次，实有" + dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate().stream().map(i -> i.getMainDutyCount() == null ? 0 : i.getMainDutyCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }

        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "8".equals(i.getSeType()) && "3".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!importantCount.equals(dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate().stream().map(i -> i.getSubDutyCount() == null ? 0 : i.getSubDutyCount()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("重要日班副排班员应有" + importantCount + "人次，实有" + dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate().stream().map(i -> i.getSubDutyCount() == null ? 0 : i.getSubDutyCount()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }
        }
    }

    private void checkBodys(DudyScheduleListVO dudyScheduleSetSaveVO, DutyScheduleSetSaveVO scheduleSetSaveVO) throws Exception {
        String[] tempArray = scheduleSetSaveVO.getSMonths().get(0).split("-");
        Long startYear = Long.valueOf(tempArray[0]);
        Long startMonth = Long.valueOf(tempArray[1]);
        tempArray = scheduleSetSaveVO.getSMonths().get(1).split("-");
        Long endYear = Long.valueOf(tempArray[0]);
        Long endMonth = Long.valueOf(tempArray[1]);
        if (endMonth < 12) {
            endMonth = endMonth + 1;
        } else {
            endMonth = 1l;
            endYear = endYear + 1;
        }
        List<ParamHolidays> holidays = paramHolidaysRepository.list(new LambdaQueryWrapper<ParamHolidays>()
                .ge(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1))
                .lt(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) endYear, (int) (long) endMonth, 1))
                .eq(ParamHolidays::getCustomId, scheduleSetSaveVO.getCustomId())
                .eq(ParamHolidays::getHolidayType, HolidaysEnum.HOLIDAY.getValue()));
        List<ParamHolidays> importantDays = paramHolidaysRepository.list(new LambdaQueryWrapper<ParamHolidays>()
                .ge(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1))
                .lt(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) endYear, (int) (long) endMonth, 1))
                .eq(ParamHolidays::getCustomId, scheduleSetSaveVO.getCustomId())
                .eq(ParamHolidays::getHolidayType, HolidaysEnum.IMPORTANT_PERIOD.getValue()));
        List<ParamHolidays> hoildayExchanges = paramHolidaysRepository.list(new LambdaQueryWrapper<ParamHolidays>()
                .ge(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) startYear, (int) (long) startMonth, 1))
                .lt(ParamHolidays::getHolidayDate, LocalDate.of((int) (long) endYear, (int) (long) endMonth, 1))
                .eq(ParamHolidays::getCustomId, scheduleSetSaveVO.getCustomId())
                .eq(ParamHolidays::getHolidayType, HolidaysEnum.HOLIDAY_EXCHANGE.getValue()));
        //24.08.02
        List<ParamScheduleSetting> rcSetting = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, scheduleSetSaveVO.getCustomId())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_RC.getValue()));
        List<ParamScheduleSetting> zmbSetting = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, scheduleSetSaveVO.getCustomId())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_ZMB.getValue()));
        List<ParamScheduleSetting> zybSetting = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, scheduleSetSaveVO.getCustomId())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_ZYB.getValue()));
        List<ParamScheduleSetting> zmSetting = paramScheduleSettingRepository.list(new LambdaQueryWrapper<ParamScheduleSetting>()
                .eq(ParamScheduleSetting::getCustomId, scheduleSetSaveVO.getCustomId())
                .eq(ParamScheduleSetting::getDutyType, SetDutyTypeEnum.TYPE_ZM.getValue()));
        Integer hoilDayCount = holidays.size() * zmbSetting.size();
        Integer importantCount = importantDays.size() * zybSetting.size();
        Integer commonCount = DateUtil.getCommonCount(startYear, startMonth, endYear, endMonth, holidays, importantDays, hoildayExchanges, rcSetting, zmSetting);
        Integer weekendCount = DateUtil.getWeekendCount(startYear, startMonth, endYear, endMonth, holidays, importantDays, hoildayExchanges, rcSetting, zmSetting);
        //24.08.02
        if (CollectionUtils.isEmpty(dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate())) {
            throw new Exception("工作日班次不能为空");
        }
        if (CollectionUtils.isEmpty(dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate())) {
            throw new Exception("工作日班次不能为空");
        }
        if (CollectionUtils.isEmpty(dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate())) {
            throw new Exception("工作日班次不能为空");
        }
        List<ParamGroupDuty> paramGroupDuties = paramGroupDutyRepository.list(new LambdaQueryWrapper<ParamGroupDuty>()
                .eq(ParamGroupDuty::getCustomId, scheduleSetSaveVO.getCustomId()));
        List<ParamGroupDuty> dailysDutys = paramGroupDuties.stream().filter(i -> "3".equals(i.getSeType()) && "1".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!commonCount.equals(dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate().stream().map(i -> i.getSectionLevelDudyNumber() == null ? 0 : i.getSectionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("工作日班科级应有" + commonCount + "人次，实有" + dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate().stream().map(i -> i.getSectionLevelDudyNumber() == null ? 0 : i.getSectionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }
        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "2".equals(i.getSeType()) && "1".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!commonCount.equals(dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate().stream().map(i -> i.getDivisionLevelDudyNumber() == null ? 0 : i.getDivisionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("工作日班处级应有" + commonCount + "人次，实有" + dudyScheduleSetSaveVO.getDailyDudy().getDudyTemplate().stream().map(i -> i.getDivisionLevelDudyNumber() == null ? 0 : i.getDivisionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }

        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "3".equals(i.getSeType()) && "4".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!weekendCount.equals(dudyScheduleSetSaveVO.getWeekendDudy().getDudyTemplate().stream().map(i -> i.getSectionLevelDudyNumber() == null ? 0 : i.getSectionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("周末科级应有" + weekendCount + "人次，实有" + dudyScheduleSetSaveVO.getWeekendDudy().getDudyTemplate().stream().map(i -> i.getSectionLevelDudyNumber() == null ? 0 : i.getSectionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }
        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "2".equals(i.getSeType()) && "4".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!weekendCount.equals(dudyScheduleSetSaveVO.getWeekendDudy().getDudyTemplate().stream().map(i -> i.getDivisionLevelDudyNumber() == null ? 0 : i.getDivisionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("周末处级应有" + weekendCount + "人次，实有" + dudyScheduleSetSaveVO.getWeekendDudy().getDudyTemplate().stream().map(i -> i.getDivisionLevelDudyNumber() == null ? 0 : i.getDivisionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }
        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "3".equals(i.getSeType()) && "2".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!hoilDayCount.equals(dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate().stream().map(i -> i.getSectionLevelDudyNumber() == null ? 0 : i.getSectionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("节假日科级应有" + hoilDayCount + "人次，实有" + dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate().stream().map(i -> i.getSectionLevelDudyNumber() == null ? 0 : i.getSectionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }
        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "3".equals(i.getSeType()) && "3".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!importantCount.equals(dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate().stream().map(i -> i.getSectionLevelDudyNumber() == null ? 0 : i.getSectionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("重要日科级应有" + importantCount + "人次，实有" + dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate().stream().map(i -> i.getSectionLevelDudyNumber() == null ? 0 : i.getSectionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }
        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "2".equals(i.getSeType()) && "2".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!hoilDayCount.equals(dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate().stream().map(i -> i.getDivisionLevelDudyNumber() == null ? 0 : i.getDivisionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0))) {
//                throw new Exception("节假日处级应有"+hoilDayCount+"人次，实有"+dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate().stream().map(DudyScheduleListVO.DudyTemplate::getDivisionLevelDudyNumber).reduce((a,b)->a+b).orElse(0)
                throw new Exception("节假日处级应有" + hoilDayCount + "人次，实有" + dudyScheduleSetSaveVO.getHolidayAndVacationsDudy().getDudyTemplate().stream().map(i -> i.getDivisionLevelDudyNumber() == null ? 0 : i.getDivisionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }
        }
        dailysDutys = paramGroupDuties.stream().filter(i -> "2".equals(i.getSeType()) && "3".equals(i.getSType()))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(dailysDutys)) {
            if (!importantCount.equals(dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate().stream().map(i -> i.getDivisionLevelDudyNumber() == null ? 0 : i.getDivisionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0))) {
                throw new Exception("重要日处级应有" + importantCount + "人次，实有" + dudyScheduleSetSaveVO.getImportantDayDudy().getDudyTemplate().stream().map(i -> i.getDivisionLevelDudyNumber() == null ? 0 : i.getDivisionLevelDudyNumber()).reduce((a, b) -> a + b).orElse(0)
                        + "人次");
            }
        }

    }


}
